Ctrl K

Words With a Given Start

Easy
A dictionary holds the words words, and a user has typed the first few letters start into a search box. The hint should show how many dictionary words begin with exactly those letters. Return the number of words in words whose first len(start) characters equal start. A word equal to start counts too. Repeated words are counted as many times as they appear.
Example 1
words=['sunrise', 'sunday', 'unsung', 'sun'], start='sun' → 3

"sunrise", "sunday" and "sun" itself begin with "sun". "unsung" contains those letters, but not at the start.

Example 2
words=['map', 'maple'], start='maples' → 0

The stem is longer than every word, so none of them qualify.

Constraints
  • 1 ≤ len(words) ≤ 100
  • 1 ≤ len(words[i]), len(start) ≤ 100
  • words[i] and start consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWords Hidden in Others EasyBookend Word Pairs EasyHighlight Search Hits MediumHighlight Search Terms MediumCapitals Follow the Pattern Medium
loading Python…
Input
words=['sunrise', 'sunday', 'unsung', 'sun'], start='sun'
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 155 tests on the server, hidden ones included.