Most Frequent Character
Updated
Problem statement
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) → StringExamples
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^4sconsists only of lowercase English letters (atoz).
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