Leetcode complains wrong answer for valid program


  • 0
    R
    static unordered_map<char, int> charmap;
    
    struct comparator
    {
    	bool operator()(char a, char b)
    	{
    		return charmap[a] > charmap[b];
    	}
    }mycomparator;
    
    class Solution {
    
    public:
    	string frequencySort(string s) {
    
    		for (char ch : s)
    		{
    			charmap[ch] += 1;
    		}
    
    		sort(s.begin(), s.end(), mycomparator);
    		return s;
    	}
    };
    

    For above code I get wrong answer for input "Aabb".
    Input:
    "Aabb"
    Output:
    "abbA"
    Expected:
    "bbAa"

    But on my machine as well as http://cpp.sh/ it prints the correct answer. Do you know why this difference


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.