New
ML System Design & SQL tracks just landed
See what's new
×
Question Bank
Pricing
Blog
Forum
HOT
JobRadar
NEW
Referral
Description
Solution
Discussion
Submissions
Ask AI
Question Bank
Square
Coding Question
AI Insights
Quick Summary
Count character frequencies and initialize a leaf node for each unique character.
Sort nodes by ascending frequency, using lexicographical order as a tie-breaker.
Iteratively merge nodes by attaching the next character as the left child and the accumulated subtree as the right child.
What This Tests
Frequency analysis using hash maps
Multi-key custom sorting logic
Iterative tree construction and reference reassignment
Greedy merging strategies
Common Patterns
Hashing
Sorting
Greedy
Collapse
Hint 1
Hint 2
What Interviewers May Ask Next
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
Qwen
Qwen3.6-Flash
0/2000
Auto
Debug
Run
Submit
Stdout
-