Word Frequency Count

Easy~10 min

Given an array of words and a target word, return how many times the target word appears in the array.

If the target word does not appear at all, return 0.

Examples

Example 1
Input: words = ["apple", "banana", "apple", "cherry", "apple"], target = "apple"
Output: 3
Explanation: "apple" appears at indices 0, 2, and 4 — three times total.
Example 2
Input: words = ["dog", "cat", "bird"], target = "fish"
Output: 0
Explanation: "fish" does not appear in the array.
Example 3
Input: words = ["hello", "hello", "hello"], target = "hello"
Output: 3
Explanation: Every element is the target word.

Constraints

  • 0 <= words.length <= 10^4
  • 1 <= words[i].length <= 100
  • 1 <= target.length <= 100
  • All strings consist of lowercase English letters.
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run