Percentage of Letter in String

Easy

Description

Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.

Examples

Input:s = "foobar", letter = "o"
Output:33
Explanation:

2/6 = 33%.

Input:s = "jjjj", letter = "k"
Output:0
Explanation:

The letter 'k' does not appear in the string at all, so 0% of characters match.

Input:s = "programming", letter = "g"
Output:18
Explanation:

The letter 'g' appears 2 times in "programming" (11 characters total). 2/11 ≈ 0.1818, so floor(18.18%) = 18%.

Constraints

  • 1 ≤ s.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!