Count one letter
Inputs
text is 0 to 24 lowercase letters (a to z). letter is one lowercase letter.
Your tasks
- Create a number
countthat starts at 0. - Use a loop over
text. Add 1 tocounteach time the character equalsletter. - Complete
countLetterso it returnscount. Return it, do not print it.
Example
With text = "banana" and letter = "a", countLetter returns 3.
Rules
- If
letternever appears, return 0.
Test data
TEST DATA 1: text is "banana", letter is "a"
TEST DATA 2: text is "", letter is "z"
Practice focus
Text is just a list of characters, so everything you know about lists applies. String problems in interviews are array problems with letters.