Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Count character frequencies using a hash map. Sort the unique characters by their frequency in descending order. Build the result by repeating each character by its count. Alternative: use bucket sort indexed by frequency for O(n) time.
The hash map captures frequency in O(n). Sorting by frequency groups characters by their count. Repeating each character by its frequency reconstructs the string in the desired order. Bucket sort variant avoids the O(n log n) comparison sort.
Updated Feb 2026