Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Counting Words With a Given Prefix

Easy
triestring

Given a prefix string s and a list of words, return how many words have s as a prefix.

Input

  • Line 1: the prefix s
  • Line 2: space-separated words

Output: the count.

Example 1
Input:
at
pay attention practice attend
Output:
2

"attention" and "attend" start with "at".

Example 2
Input:
code
leetcode win loops success
Output:
0

Constraints

  • 1 ≤ words.length ≤ 100
  • 1 ≤ word and prefix lengths ≤ 100
  • Lowercase English letters.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.