fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int twiceIndex(int[] arr) {
  11.  
  12. int maxIndex = 0;
  13.  
  14. for (int i = 0; i < arr.length; ++i) {
  15. if (arr[i] > arr[maxIndex])
  16. maxIndex = i;
  17. }
  18. for (int i = 0; i < arr.length; ++i) {
  19. if (maxIndex != i && arr[maxIndex] < 2 * arr[i])
  20. return -1;
  21. }
  22. return maxIndex;
  23. }
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. // your code goes here
  27. int[] arr = {3, 6, 0, 1};
  28.  
  29. System.out.println(twiceIndex(arr));
  30. }
  31. }
Success #stdin #stdout 0.08s 27716KB
stdin
Standard input is empty
stdout
1