Here you can find the source of maxRepeating(int[] input, int k)
static int maxRepeating(int[] input, int k)
//package com.java2s; //License from project: Apache License public class Main { static int maxRepeating(int[] input, int k) { // Iterate though input array, for every element // input[i], increment input[input[i]%k] by k for (int i = 0; i < input.length; i++) { // System.out.println(input[i]%k); int indexToIncrease = input[i] % k; input[indexToIncrease] = input[indexToIncrease] + k; }/* www . ja v a 2 s . c o m*/ // Find index of the maximum repeating element int max = input[0], result = 0; for (int i = 1; i < input.length; i++) { if (input[i] > max) { max = input[i]; result = i; } } /* Uncomment this code to get the original array back*/ for (int i = 0; i < input.length; i++) input[i] = input[i] % k; // Return index of the maximum element return result; } }