Skip to main content
All Questions

Design a unique string generator for URL shortening with a character frequency threshold.

Unlock detailed company stats for this questionUpgrade

Design a class that generates unique strings for URL shortening. Strings use only lowercase a-z; a threshold T is given and the frequency of any character in a generated string must be <= T; each call returns a unique string; shorter strings must be returned before longer ones (order within the same length does not matter). API: class URLShortener { URLShortener(int threshold); string getNext(); } Example with T = 2: a, b, c, ..., z, then aa, ab, ac, ..., zz (every character appears at most 2 times). Base-26 enumeration with carry works, skipping invalid strings (e.g. with T = 2, 110 and 112 are valid but 111 is not).

Format · Google L4 onsite.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.