FastPrepSort Characters by How Often They Appear
Problems/Sort Characters by How Often They Appear

Sort Characters by How Often They Appear

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You rearrange a string so that its most frequent characters come first, with a fixed rule for ties. An Adobe MTS 2 report from Noida (October 2024, covering interviews from July to September) lists it as the first question of its first problem-solving round. Its examples show that characters with equal counts could come in either order. The candidate described several approaches and coded one with a max-heap. The interviewer then asked whether the sorting step could be avoided. The candidate thinks this pointed to grouping characters by count.

We chose these rules. Ties go to the smaller character code, so exactly one answer is correct. Strings hold only letters and digits, with 1 to 5000 characters. We wrote new examples. The editorial teaches the count-grouping (bucket) approach that avoids sorting.

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

Given a string s, rearrange its characters so that characters that appear more often come first. All copies of a character stay together.

If two characters appear the same number of times, the one with the smaller character code (ASCII value) comes first. So digits come before uppercase letters, and uppercase letters before lowercase ones. Uppercase and lowercase forms are different characters.

Return the rearranged string.

Function

frequencySort(s: String) → String

Examples

Example 1

s = "banana"return = "aaannb"

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

Example 2

s = "dcba"return = "abcd"

All four characters appear once, so the tie rule decides: smallest character code first, which gives abcd.

Example 3

s = "zZz9Z9"return = "99ZZzz"

9, Z and z each appear twice. Digits come before uppercase letters, and uppercase before lowercase, so the order is 99, ZZ, zz.

Constraints

  • 1 <= s.length <= 5000
  • s contains only English letters (uppercase and lowercase) and digits

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
  • Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Top N Frequent Words in a FileMeta · PHONE SCREENMeta interview questions
  • Top K Keys from JSON RecordsCapital One · ONSITE INTERVIEWCapital One interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Top K Movies by Play Count from CSV DataTubi · PHONE SCREEN
  • Group AnagramsWorkday · PHONE SCREEN
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Bank Account Balances (Part 2): Monthly ReconciliationStripe · PHONE SCREENStripe interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions

Interview reports that mention this question

  • Adobe MTS Interview Questions: 12 Experiences (Part 2 of 6)
  • Adobe Experienced Hire Interviews: 55 Experiences (Part 1 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public String frequencySort(String s) {
        // Write your code here.
    }
}
Checking account…