Java Array Max Value maxRepeating(int[] input, int k)

Here you can find the source of maxRepeating(int[] input, int k)

Description

max Repeating

License

Apache License

Declaration

static int maxRepeating(int[] input, int k) 

Method Source Code

//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;
    }
}

Related

  1. maxOverArraySubset(double[] array, Iterable subset)
  2. maxpool(float[] curr, float[] probs)
  3. maxPosition(float[] v)
  4. maxPositive(int[] array)
  5. maxPrim(final int... numbers)
  6. maxRow(Object[]... arr)
  7. maxRowLen(Object[]... arr)
  8. maxSize(String[] string)
  9. maxSort(double[] arr)