• + 0 comments
    unordered_map<char, int> ladybug;
         int flag = 0;
         //counting frequency of character
         for(int i = 0; i< b.size(); i++){
            ladybug[b[i]]++;
         }
         
         //checking the count of the character greater than 1
         if(ladybug.size() > 1){
            for(int i = 0; i< ladybug.size(); i++){
                char c = i+ 65;
                if(ladybug[c]== 1 && c != '_') return "NO";
            }
         }
         
         //checking if any possible chance to switch 
         for(auto i : ladybug){
            if(i.first == '_'){flag = 1; break;}
         }
         
         // checking it is sorted or not if there is no chance to switch
         if(flag == 0){
            for(int i = 0; i< b.size();i++){
                if(b[i] == b[i+1] || b[i] == b[i-1]){
                    flag = 1;
                }else{
                    flag = 0;
                    break;
                }
            }
         }
         
         return  flag == 0 ? "NO" : "YES";