classSolution{publicintminimumIndex(List<Integer> nums){int[] dominant =newint[]{0,0};// Number -> countHashMap<Integer,Integer> map =newHashMap();// Find the dominant elementfor(int num : nums){
map.put(num,1+ map.getOrDefault(num,0));// Update the dominant elementif(dominant[1]< map.get(num)){
dominant[0]= num;
dominant[1]= map.get(num);}}int currentDominantCount =0;for(int i =0; i < nums.size();++i){// When encounter dominant valueif(nums.get(i)== dominant[0]){++currentDominantCount;}int secondDominantCount = dominant[1]- currentDominantCount;// When dominant dominates// Times 2 or divided by two ((i + 1) / 2) || ((nums.size() - i - 1) / 2) are both valid, since the point is to check the elements are more than half of the rangeif(currentDominantCount *2>(i +1)&& secondDominantCount *2>(nums.size()- i -1)){return i;}}return-1;}}