Code is working as intended, returning minimum value and index. Showing correct output when I run the program but unable to verify.
package com.codegym.task.task12.task1233;
/*
The isomorphs are coming
*/
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
Pair<Integer, Integer> result = getMinimumAndIndex(data);
System.out.println("Minimum is " + result.x);
System.out.println("Index of minimum element is " + result.y);
}
public static Pair<Integer, Integer> getMinimumAndIndex(int[] array) {
if (array == null || array.length == 0) {
return new Pair<Integer, Integer>(null, null);
}
//write your code here
else{
Integer[] temp = new Integer[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
Integer index=0;
Arrays.sort(temp);
for (Integer i=0;i<array.length;i++){
if(temp[0] == array[i]) {
index = i;
break;
}
}
Integer minimum = temp[0];
return new Pair<Integer, Integer>(minimum, index);
}
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}