Most Frequent Letter with First-Appearance Ties
Updated
Problem statement
Return the most frequent letter in s. If multiple letters have the same maximum frequency, return the one whose first occurrence appears earliest in the original string.
For this exercise, assume the input contains lowercase English letters. Return the selected letter as a one-character string. An empty input returns an empty string. A lexicographically smaller letter does not win a tie unless it also appears first.
Function
mostFrequentLetter(s: String) → StringExamples
Example 1
s = "banana"return = "a"a occurs 3 times, more often than b or n.
Example 2
s = "baba"return = "b"a and b each occur twice. b appears first in the original string.
Example 3
s = ""return = ""An empty string contains no letter.
Constraints
0 <= s.length <= 10000.- Every character is a lowercase English letter.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Branch with the Most FilesCapital One · OACapital One interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
- Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions