Reorder a Gboard Suggestion String by Letter Frequency
Last updated: November 29, 2026
Quick Overview
Given a string, return it rearranged so that characters appear in descending order of how often they occur, with all copies of a character grouped together.
0
0
0 solved
Given a string, return it rearranged so that characters appear in descending order of how often they occur, with all copies of a character grouped together.
A light Google phone-screen question framed around Gboard keyboard analytics. The interviewer checks counting plus ordering and whether the candidate knows the bucket approach that removes the log factor.
What the Interviewer Expects
- Counts characters with a hash map
- Orders by count using a heap or buckets
- Groups identical characters together
- Mentions O(n) bucket sort
- Agrees on tie-breaking
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Make the output deterministic for ties
- How would you handle Unicode grapheme clusters?
- Return only the top k characters instead
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: a string of any characters, possibly empty.
- Output: same multiset of characters, grouped and sorted by decreasing frequency.
- Ties: break by character code ascending so the answer is deter...
High-Level Design
Two steps. First count every character in one pass with a Counter. Second, emit characters in descending count. A max-heap of (-count, char) pops them in the right order and the tuple comparison h...