/**
* Find the element with maximum frequency
* @author PRATEEK
*/
class MaxRepeatingNumer {
public static void main
(String[] args
) {
int arr[] = { 3, 1, 3, 2, 1, 2, 2 };
int x = 5;
System.
out.
println(maxRepeatingNumer
(arr, x
)); }
private static int maxRepeatingNumer(int arr[],int k) {
int i = 0, max = arr[0], result = 0;
for (; i < arr.length; i++)
arr[arr[i] % k] += k;
i = 1;
for (; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
result = i;
}
}
i = 0;
for (; i < arr.length; i++)
arr[i] = arr[i] % k;
return result;
}
}
LyoqCiAqIEZpbmQgdGhlIGVsZW1lbnQgd2l0aCBtYXhpbXVtIGZyZXF1ZW5jeQogKiBAYXV0aG9yIFBSQVRFRUsKICovCmNsYXNzIE1heFJlcGVhdGluZ051bWVyIHsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKCgkJaW50IGFycltdID0geyAzLCAxLCAzLCAyLCAxLCAyLCAyIH07CgkJaW50IHggPSA1OwoJCVN5c3RlbS5vdXQucHJpbnRsbihtYXhSZXBlYXRpbmdOdW1lcihhcnIsIHgpKTsKCX0KCglwcml2YXRlIHN0YXRpYyBpbnQgbWF4UmVwZWF0aW5nTnVtZXIoaW50IGFycltdLGludCBrKSB7CgkJCgkJaW50IGkgPSAwLCBtYXggPSBhcnJbMF0sIHJlc3VsdCA9IDA7CgkJZm9yICg7IGkgPCBhcnIubGVuZ3RoOyBpKyspCgkJCWFyclthcnJbaV0gJSBrXSArPSBrOwoKCQlpID0gMTsKCQlmb3IgKDsgaSA8IGFyci5sZW5ndGg7IGkrKykgewoJCQlpZiAoYXJyW2ldID4gbWF4KSB7CgkJCQltYXggPSBhcnJbaV07CgkJCQlyZXN1bHQgPSBpOwoJCQl9CgkJfQoKCQlpID0gMDsKCQlmb3IgKDsgaSA8IGFyci5sZW5ndGg7IGkrKykKCQkJYXJyW2ldID0gYXJyW2ldICUgazsKCgkJcmV0dXJuIHJlc3VsdDsKCX0KfQ==