I have an array that contains numbers.
I got the two minimum values (can be the same number) of this array in O(N) but i cant figure out how to get the index of this two values.
For example: in {1,2,3,1,5} the answer will be index 0 and index 3. this is the code i'm using:
public static void minMin(int arr[]){
int min1 = weights[0], min2 = weights[1];
if(min1 > min2){
int temp = min1;
min1 = min2;
min2 = temp;
}
for (int i = 2; i < weights.length; i++) {
if(weights[i] < min1){
int temp = min1;
min1 = weights[i];
min2 = temp;
}else if(weights[i] < min2){
min2 = weights[i];
}
}
}