package cokr.xit.problems;

import org.junit.jupiter.api.Test;

import java.util.*;

class Solution2 {


    @Test
    public void main(){

        String call = null;



        call = "abcabcdefabc";
        System.out.println(solution(call));

        call = "abxdeydeabz";
        System.out.println(solution(call));

        call = "abcabca";
        System.out.println(solution(call));

        call = "ABCabcA";
        System.out.println(solution(call));
    }

    private String solution(String call){
        String answer = "";



        Map<String, Integer> map = new HashMap();
        for(int i=0; i<call.length(); i++){
            String ch = call.substring(i, i+1);
            map.put(ch.toLowerCase(), map.getOrDefault(ch.toLowerCase(), 0)+1);
        }

        String maxCntKey = Collections.max(map.entrySet(), Comparator.comparingInt(Map.Entry::getValue)).getKey();
        int maxCnt = map.get(maxCntKey);

        Iterator<String> it = map.keySet().iterator();
        while(it.hasNext()){
            String key = it.next();
            int value = map.get(key);
            if(maxCnt == value){
                call = call.replace(key, "").replaceAll(key.toUpperCase(), "");
            }
        }

        return call;
    }



}