With these it helps I have a problem that keep bugging me out. Finding the smallest number in array is easy but here is my problem; when you find the smallest number in array , the smallest number becomes a[0] th element of array. What i want is , i want to find the smallest number and also which element it is. Such as this , You could leverage IntStream.range in such case: code :
IntStream.range(0, arr.length)
.mapToObj(index > new SimpleEntry<>(index, arr[index]))
.min(Comparator.comparingInt(SimpleEntry::getValue));
int[] arr = new int[]{5,20 ,1 ,12};
IntStream.range(0, arr.length)
.mapToObj(index > new SimpleEntry<>(index, arr[index]))
.min(Comparator.comparingInt(SimpleEntry::getValue))
.ifPresent(s > System.out.println(s.getValue()+
" is the smallest number and it's index" + s.getKey() + "of array"));
Share :

How do I find the smallest number in an array that's immediately larger than a given number in another array?
By : Sakis Korelidis
Date : March 29 2020, 07:55 AM

Find the smallest and second smallest number in an array of 8 numbers with only 9 comparisons
By : user2402655
Date : March 29 2020, 07:55 AM
should help you out A way to think about the solution is this is like a tennis knockoff competition series. Suppose each number corresponds to a player. Pair off the numbers and let each game correspond to a comparison between numbers within a pair: Games: (a1,a2), (a3, a4), (a5, a6), (a7, a8) code :
a12345678
/ \
/ \
/ \
/ \
a1234 a5678
/ \ / \
/ \ / \
a12 a34 a56 a78
/ \ / \ / \ / \
a1 a2 a3 a4 a5 a6 a7 a8
a3

/\
/ \
/ \
/ \
a3 >==========> a5678
/ \ / \
/ \ / \
a12 <====< a3 a56 a78
/ \ / \ / \ / \
a1 a2 a3 >a4 a5 a6 a7 a8

Find smallest number K , if exists, such that product of its digits is N. Eg:when N = 6, smallest number is k=16(1*6=6)
By : user3782818
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have made this program using array concept in java. I am getting Exception as ArrayIndexOutOfBound while trying to generate product. , Problem lies in this line code :
String t=x[d++]+""+x[p];

How do I find the Index of the smallest number in an array in python if I have multiple smallest numbers and want both i
By : Todd Preston
Date : March 29 2020, 07:55 AM
I hope this helps you . You may enumerate array elements and extract their indexes if the condition holds: code :
min_value = min(distance)
[i for i,n in enumerate(distance) if n==min_value]
#[0,2]

Why is this code to find the minimum number in an array assuming the first element is smallest?
By : ccullen
Date : March 29 2020, 07:55 AM
help you fix your problem , The problem in your code is b is local variable to the this for loop

