Birthday Cake Candles

  • + 0 comments
    public static int birthdayCakeCandles(List<Integer> candles) {
        // Write your code here
            Map<Integer, Integer> map = new HashMap<>();
            int maxValue = 0;
        
            for (int i = 0; i < candles.size(); i++) {
                if (map.containsKey(candles.get(i))) {
                    int currentValue = map.get(candles.get(i)) + 1;
                    map.put(candles.get(i), currentValue);
                    if (currentValue > maxValue) {
                        maxValue = currentValue;
                    }
                } else {
                    map.put(candles.get(i), 1);                
                }
            }
            
            return maxValue;
        }