/*
Given a string, return a new string of equal length with the same
characters rearranged in decreasing order of number of occurrences. In
the case of two or more distinct characters occurring the same number
of times, order them by increasing character code.
This is a basic test of programming language familiarity with
little reliance on runtime library. It also requires basic algorithm construction, but nothing fancy.
Hint:
Example: given "This is a sample string",
return "ssssiiiaaTeghlmnprrt"
*/
This task requires you to sort characters in a string by:
✅ Rules
- Frequency descending
- If frequencies tie → character code ascending
- Output length must match input length
✅ Approach
- Count character frequencies using a map
- Sort characters by
(−frequency, +ASCII) - Reconstruct the output string by repeating each character according to its count
This tests basic algorithm design and comfort with the language, without relying heavily on advanced libraries.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including OpenAI, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.