Skip to content

Instantly share code, notes, and snippets.

public class Rare {
public static int nthMostRare(int[] elements, int n) {
final Map<Integer, Integer> map = new HashMap<>();
for (int i: elements)
{
map.compute(i, (k, v) -> {
if (k == null) {
return 1;
} else {
if (v == null) return 1;