FastPrepSort Letters by Frequency
Problems/Sort Letters by Frequency

Sort Letters by Frequency

Scale AI logoScale AI● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2024 Scale AI SWE intern report says the live coding round asked the candidate to sort the letters of a string by their counts.

The report names only the task. It does not say whether common letters go first or last, how to order letters with the same count, which characters can appear, or how long the string can be. Here, more frequent letters go first, ties go in alphabetical order, the string has only lowercase letters, and the length limit is our choice.

Our version is about 80% the same as the reported question.

You are given a string s made of lowercase English letters. Reorder its letters by how many times each letter appears:

  • A letter that appears more times comes before a letter that appears fewer times.
  • If two letters appear the same number of times, the one that comes first in the alphabet goes first.

Keep every copy. A letter that appears k times shows up k times in a row in the answer. Return the reordered string.

Function

sortLettersByFrequency(s: String) → String

Examples

Example 1

s = "banana"return = "aaannb"

a appears 3 times, n appears 2 times and b appears once. So the answer is aaa, then nn, then b.

Example 2

s = "mississippi"return = "iiiissssppm"

i and s each appear 4 times. They tie, so i goes first because it comes first in the alphabet. Then come p (2 times) and m (1 time).

Example 3

s = "zebra"return = "aberz"

Every letter appears once. All counts tie, so the letters go in alphabetical order.

Constraints

  • 1 <= s.length <= 5000
  • s consists only of lowercase English letters.

More Scale AI Phone Screen questions

  • Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
  • Task Processor: Dependencies and DeadlinesPHONE SCREEN · Seen Aug 2026
  • Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
  • Free Time for Every Meeting RoomPHONE SCREEN · Seen Apr 2026
  • Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
  • Order Queries by Shortest Processing TimePHONE SCREEN · Seen Apr 2026
  • Party Time by Town and Quiet Gaps by CityPHONE SCREEN · Seen Jan 2026
  • Party Windows and Dead Zone TimePHONE SCREEN · Seen Oct 2025
  • Overlap Duration of Two Time IntervalsPHONE SCREEN · Seen Jun 2025
  • Multi-Head Attention BlockPHONE SCREEN · Seen Mar 2025

Similar questions at other companies

  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
  • Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Best Anagram MatchGoogle · PHONE SCREENGoogle interview questions
  • Word Frequency in a Large TextRobinhood · PHONE SCREENRobinhood interview questions
  • Remove Later Anagrams From a ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Employees With Shared InterestsPalantir · PHONE SCREENPalantir interview questions
  • Rank Words by FrequencyDatadog · PHONE SCREENDatadog interview questions
  • Average Process Time from CSVAbnormal Security · PHONE SCREEN

Interview reports that mention this question

  • Scale AI SWE Intern Debugging Interview: 9 Experiences

Scale AI interview experiences

  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
  • Scale AI ML Research Engineering Intern Interviews: 1 Experience
  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad SWE Poker Screen and Onsite: 1 Experience
  • Scale AI New Grad SWE OA Questions: 1 Experience
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public String sortLettersByFrequency(String s) {
        // Write your code here.
    }
}
Checking account…