303. Sort Characters by Frequency

You are given a string s. Return the array of unique characters, sorted by highest to lowest occurring characters.

If two or more characters have same frequency then arrange them in alphabetic order.

Example 1:

Input : s = "tree"

Output : ['e', 'r', 't' ]

Explanation :

The occurrences of each character are as shown below :

e --> 2

r --> 1

t --> 1.

The r and t have same occurrences , so we arrange them by alphabetic order.

Example 2:

Input : s = "raaaajj"

Output : ['a' , 'j', 'r' ]

Explanation :

The occurrences of each character are as shown below :

a --> 4

j --> 2

r --> 1

Now Your Turn!

Pick the correct output for the given input

Input : s = "bbccddaaa"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consist of only lowercase English characters.

Fun Facts

0
class Solution{
public:
vector<char> frequencySort(string& s){
//your code goes here
}
};
Test Case

Input:

S