Showing posts with label Find second biggest number from array in react- native. Show all posts
Showing posts with label Find second biggest number from array in react- native. Show all posts

Thursday 22 June 2023

How to find second largest number in array without sorting in React-Native

Here is  java script  practical example for find second largest biggest Number from the array:


let m1 = [90, 45, 34, 67, 999, 76, 34, 89, 99, 23];

let No1 = 0;

let No2 = 0;

let mcounter = m1.length - 2;

for (let m = 0; m < m1.length; m++) {

  let sR = m1[m];

  if (mcounter == m) {

    break;

  }

  if (sR > No1) {

    No2 = No1; // Store the current No1 as No2

    No1 = sR; // Update No1 with the new bigger value

  } else if (sR > No2 && sR < No1) {

    No2 = sR; // Update No2 with the new second biggest value

  }

}


console.log("Second biggest number: " + No2);


Out put will be:

Second biggest number: 99

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...