private Entry<Integer, Integer> maxValue(Map<Integer, Integer> frequency) {
        Entry<Integer, Integer> bestEntry = null;
        for (Entry<Integer, Integer> entry : frequency.entrySet()) {
            if (bestEntry == null || bestEntry.getValue() < entry.getValue()) {
                bestEntry = entry;
            }
        }
        return bestEntry;
    }