FastPrepMost Frequent Character
Problems/Most Frequent Character

Most Frequent Character

Microsoft logoMicrosoft● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Finding the character that shows up most often in a string was the first of two questions in a Microsoft intern online assessment report. The author found it very easy.

The report gives no input limits and does not say what to do when two characters tie. Here the string has 1 to 10^4 lowercase English letters, a tie goes to the letter that comes first in the alphabet, and you return the letter as a one-character string.

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

You are given a string s. Return the letter that appears the most times in s, as a string of length 1.

If more than one letter shares the highest count, return the one that comes first in the alphabet.

Function

mostFrequentCharacter(s: String) → String

Examples

Example 1

s = "banana"return = "a"

The letter a appears 3 times, n appears 2 times and b appears once, so the answer is "a".

Example 2

s = "programming"return = "g"

The letters g, m and r each appear 2 times, and every other letter appears once. Of the three tied letters, g comes first in the alphabet, so the answer is "g".

Example 3

s = "z"return = "z"

The only letter is z.

Constraints

  • 1 <= s.length <= 10^4
  • s consists only of lowercase English letters (a to z).

More Microsoft Online Assessment questions

  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026
  • Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
  • Flat JSON Value DifferencesChubb · OAChubb interview questions
  • Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
  • Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
  • Get Maximum Information GainAmazon · OA
  • Better CompressionGoldman Sachs · OAGoldman Sachs interview questions
  • Process LogsSnowflake · OASnowflake interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String mostFrequentCharacter(String s) {
        // Write your code here.
    }
}
Checking account…