Birthday Cake Candles

  • + 0 comments

    Java Solution

        public static int birthdayCakeCandles(List<Integer> candles) {
        // Write your code here
            HashMap<Integer,Integer> maps = new HashMap<>();
            for(int num : candles){
                if(maps.containsKey(num)){
                    maps.put(num, maps.get(num)+1);
                }
                else {    
                maps.put(num, 1);
                }
            }
            int maxEle = maxing(candles);
            return maps.get(maxEle);
            
        }
        public static int maxing (List<Integer> arr){
            int max = arr.get(0) ;
            for(int i = 0 ; i<arr.size(); i++){
                if(max < arr.get(i)){
                    max=arr.get(i);
                }
            }
            return max;
        }