2
public int[] rearrangeBarcodes(int[] barcodes) {4
if (barcodes.length <= 2) {5
return barcodes; // Problem says solution always exist.8
Map<Integer, Integer> count = new HashMap<>();9
Integer maxKey = null; // Character having max frequency11
for (int i : barcodes) {12
count.put(i, count.getOrDefault(i, 0) + 1);13
if (maxKey == null || count.get(i) > count.get(maxKey)) {21
int curr = count.get(maxKey);23
barcodes[pos] = maxKey;25
if (pos >= barcodes.length) {30
count.remove(maxKey); // Since that character is done, we don't need to fill it again32
// Fill the remaining Characters.33
for (int key : count.keySet()) {34
curr = count.get(key);39
if (pos >= barcodes.length) {