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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Hash Map
Heap
Bucket Sort
Strings
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported