We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
ALL CASES RUNNING
import java.io.;
import java.util.;
import java.math.;
import java.util.regex.;
import java.text.*;
public class solution{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i = 0; i
}
int min = Integer.MAX_VALUE;
for(int i = 0; i < n ; i++){
for (int j = i+1; j < n; j++) {
if (a[i] == a[j]){
int temp = j - i;
if(temp < min){
min = temp;
}
}
}
}
if(min == Integer.MAX_VALUE)
min = -1;System.out.println(min);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Distances
You are viewing a single comment's thread. Return to all comments →
ALL CASES RUNNING import java.io.; import java.util.; import java.math.; import java.util.regex.; import java.text.*; public class solution{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[n]; for(int i = 0; i
}