Grokking the Coding Interview: Patterns for Coding Questions

0% completed

Solution: Frequency Sort

Problem Statement

Given a string, sort it based on the decreasing frequency of its characters.

Example 1:

Input: "Programming"
Output: "rrggmmPiano"
Explanation: 'r', 'g', and 'm' appeared twice, so they need to appear before any other character.

Example 2:

Input: "abcbab"
Output: "bbbaac"
Explanation: 'b' appeared three times, 'a' appeared twice, and 'c' appeared only once.

Constraints:

  • 1 <= str.length <= 5 * 10<sup>5</sup>
  • str consists of uppercase and lowercase English letters and digits.

.....

.....

.....

Like the course? Get enrolled and start learning!
W

Will

· 4 years ago

Again, the O(N) Bucket Sort solution can be applied to this question too, as it is the same style as the previous question.

Show 2 replies
P

Parth Saxena

· 4 years ago

Hi could someone else to me when to us Map.entry. I am a bit confused

Show 2 replies