fork download
  1. import java.util.HashSet;
  2. import java.util.Set;
  3.  
  4. public class Main
  5. {
  6. public static void main(String[] args)
  7. {
  8. int[] test = {1, 2, 3, 4, 5, 5};
  9. System.out.println(minRepeatIndex(test));
  10.  
  11. }
  12.  
  13. private static String minRepeatIndex(int[] test)
  14. {
  15. Integer minIndex = -1;
  16. Set<Integer> elements = new HashSet<Integer>();
  17. for(int i = test.length - 1; i >= 0; i--)
  18. {
  19. if(!elements.add(test[i]))
  20. {
  21. minIndex = i;
  22. }
  23.  
  24. }
  25. return minIndex.toString();
  26. }
  27. }
Success #stdin #stdout 0.07s 2841600KB
stdin
Standard input is empty
stdout
4