FastPrepMost Frequent Letter with First-Appearance Ties

Most Frequent Letter with First-Appearance Ties

Roblox logoRoblox● EasyFULLTIMEOA
Learn

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) → String

Examples

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 problems

See Roblox hiring insights
public String mostFrequentLetter(String s) {
    // write your code here
}
s"banana"
expected"a"
Checking account…