Answer: EMERSON ELECTRIC | On-Campus OA (2024) | Percentage of Letter in String

Answer · Posted Jun 2026

Approach Traverse the string and count occurrences of the given letter. Compute the percentage using: (count × 100) / length Integer division automatically rounds down. Strategy Initialize a counter. Iterate through the string. Increase the counter whenever the current character equals the given letter. Return the calculated percentage. Java Code class Solution { public int percentageLetter(String s, char letter) { int count = 0; for (char c : s.toCharArray()) { if (c == letter) count++; } return (count * 100) ...

The full answer & interview discussion are available to premium members.

Log in Create a free account