import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main
(String[] args
) { int n = 6;
int[] arr = {1, 1, 2, 3, 3, 3};
Map
<Integer, Integer
> mp
= new HashMap
<>(); int maxiFreq
= Integer.
MIN_VALUE, maxiElement
= arr
[0]; int miniFreq
= Integer.
MAX_VALUE, miniElement
= arr
[0];
for (int i = 0; i < arr.length; i++) {
mp.put(arr[i], mp.getOrDefault(arr[i], 0) + 1);
}
for (Map.
Entry<Integer, Integer
> num
: mp.
entrySet()){ if (num.getValue() >= maxiFreq){
maxiFreq = num.getValue();
maxiElement = num.getKey();
}
if (num.getValue() <= miniFreq){
miniFreq = num.getValue();
miniElement = num.getKey();
}
}
System.
out.
println("Max frequency element: " + maxiElement
+ " with frequency: " + maxiFreq
); System.
out.
println("Min frequency element: " + miniElement
+ " with frequency: " + miniFreq
); }
}
aW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLk1hcDsKIApwdWJsaWMgY2xhc3MgTWFpbiB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgaW50IG4gPSA2OwogICAgICAgIGludFtdIGFyciA9IHsxLCAxLCAyLCAzLCAzLCAzfTsKIAogICAgICAgIE1hcDxJbnRlZ2VyLCBJbnRlZ2VyPiBtcCA9IG5ldyBIYXNoTWFwPD4oKTsKICAgICAgICBpbnQgbWF4aUZyZXEgPSBJbnRlZ2VyLk1JTl9WQUxVRSwgbWF4aUVsZW1lbnQgPSBhcnJbMF07CiAgICAgICAgaW50IG1pbmlGcmVxID0gSW50ZWdlci5NQVhfVkFMVUUsIG1pbmlFbGVtZW50ID0gYXJyWzBdOwogCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhcnIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgbXAucHV0KGFycltpXSwgbXAuZ2V0T3JEZWZhdWx0KGFycltpXSwgMCkgKyAxKTsKICAgICAgICB9CiAKICAgICAgICBmb3IgKE1hcC5FbnRyeTxJbnRlZ2VyLCBJbnRlZ2VyPiBudW0gOiBtcC5lbnRyeVNldCgpKXsKICAgICAgICAgICAgaWYgKG51bS5nZXRWYWx1ZSgpID49IG1heGlGcmVxKXsKICAgICAgICAgICAgICAgIG1heGlGcmVxID0gbnVtLmdldFZhbHVlKCk7CiAgICAgICAgICAgICAgICBtYXhpRWxlbWVudCA9IG51bS5nZXRLZXkoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAobnVtLmdldFZhbHVlKCkgPD0gbWluaUZyZXEpewogICAgICAgICAgICAgICAgbWluaUZyZXEgPSBudW0uZ2V0VmFsdWUoKTsKICAgICAgICAgICAgICAgIG1pbmlFbGVtZW50ID0gbnVtLmdldEtleSgpOwogICAgICAgICAgICB9CiAgICAgICAgfQogCiAKIAogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiTWF4IGZyZXF1ZW5jeSBlbGVtZW50OiAiICsgbWF4aUVsZW1lbnQgKyAiIHdpdGggZnJlcXVlbmN5OiAiICsgbWF4aUZyZXEpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiTWluIGZyZXF1ZW5jeSBlbGVtZW50OiAiICsgbWluaUVsZW1lbnQgKyAiIHdpdGggZnJlcXVlbmN5OiAiICsgbWluaUZyZXEpOwogICAgfQp9