Jitendra Kumar
I have a array like {12,13,24,45,65,27,37,43,41,50,75,68}. Write a method or logic to get 3rd largest value in the array in only Single Loop is use without using sort.
By Jitendra Kumar in .NET on Oct 04 2016
  • sajid ali
    Jul, 2019 30

    int[] array= new int[]{12,13,24,45,65,27,37,43,41,50,75,68};
    var item = array.OrderByDescending(x=>x).Skip(2).Take(1).ToList();
    foreach(int it in item)
    Console.WriteLine(it);

    • 1
  • mukesh kumar
    Oct, 2018 3

    var result = from n in number orderby n descending select n; var value = result.ToList().ElementAt(2);

    • 1
  • Satyendra Patel
    May, 2018 28

    class Test{public int Third_higest(int[] array){// int[] array = new int[12] { 12, 13, 67, 45, 65, 27, 37, 43, 41, 50, 75, 68 };int arrLen = array.Length - 1;int indexofi = 0, temp = 0, count = 0, indexofj = 0, index = 0, breakpoint = 0;while (true){if (indexofj == arrLen){if (indexofi != arrLen){indexofi++;}if (count == 3){break;}indexofj = 0;}if (array[indexofi] < array[indexofj + 1]){temp = array[indexofi];array[indexofi] = array[indexofj + 1];array[indexofj + 1] = temp;temp = array[indexofi];indexofj++;}else{indexofj++;}if (temp != 0 && indexofj == arrLen && indexofi == count){array[indexofi] = 0;count++;}// if (arrLen == index)// {// if (breakpoint == 0)// {// break;// }// index = 0;// breakpoint = 0;// }// if (array[index] < array[index + 1])// {// int tmp = array[index];// array[index] = array[index + 1];// array[index + 1] = tmp;// breakpoint = 1;// }// index++;// temp++;//}}return temp;}}class Program{static void Main(string[] args){Test test = new Test();int[] array = new int[12] { 12,13,24,45,65,27,37,43,41,50,75,68};int arrayOut = test.Third_higest(array);Console.WriteLine(arrayOut);Console.ReadLine();}}

    • 1
  • Surendra Pal Singh
    Apr, 2018 27

    for (var i = 1; i < array.Length;){if (i != 0 && (array[i] < array[i - 1])){var temp = array[i];array[i] = array[i - 1];array[i - 1] = temp;i--;}else { i++; }}

    • 1
  • Mahendra Kumar
    Apr, 2019 2

    public int thirdlargestValue(){int first, second, third = 0;int[] arr = { 12, 13, 24, 45, 65, 27, 37, 43, 41, 50, 75, 68 };first = arr[0];second = arr[1];third = arr[2];for (int i = 0; i < arr.Length; i++){if (arr[i] > first){third = second;second = first;first = arr[i];}else if (arr[i] > second){third = second;second = arr[i];}else if (arr[i] > third){third = arr[i];}}return third;}

    • 0
  • Bheema Shankar Maruvada
    Dec, 2018 24

    int[] nums = new int[] {12,13,24,45,65,27,37,43,41,50,75,68}var result = (from s in numsselect s).skip(2).first();

    • 0
  • Surendra Pal Singh
    Apr, 2018 27

    for (var i = 1; i < array.Length;){if (i != 0 && (array[i] < array[i - 1])){var temp = array[i];array[i] = array[i - 1];array[i - 1] = temp;i--;}else { i++; }}

    • 0
  • Naresh Tottempudi
    Mar, 2018 1

    for(int i=0;i<=array.Length-1;i ) {if(array[i]

    • 0
  • Sheel  dUBEY
    May, 2017 10

    public void GetThirdHigestNumber(){int[] array = { 12, 13, 24, 45, 65, 27, 37, 43, 41, 50, 75, 68 };var objResult = array.OrderByDescending(x => x).ToList().Take(3);int thirdHighestNumber = 0;foreach (int num in objResult){thirdHighestNumber = num;}Console.WriteLine("Third Hieghest Number : {0}", thirdHighestNumber);}

    • 0
  • Naveen Kumar
    Mar, 2017 19

    public static int thirdLargestNumber(int[] numbers){for(int i=0;i

    • 0
  • Prasant Maharana
    Mar, 2017 2

    int iCount = 0;int[] array = new int[12] { 12, 13, 24, 45, 65, 27, 37, 43, 41, 50, 75, 68 };for (int i = 0; i <= array.Length; i++){for (int j = i + 1; j < array.Length; j++){if (array[i] > array[j]){iCount = array[i];array[i] = array[j];array[j] = iCount;}}}Console.WriteLine(array[2]);

    • 0
  • Rajeev Ranjan
    Feb, 2017 24

    int[] arr={12,13,24,45,65,27,37,43,41,50,75,68};var q = arr.OrderByDescending(a => a).ToArray();for (int i = 0; i < q.Count(); i++ ){if (i == 2){Console.WriteLine(q[i].ToString());break;}}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS