Tap here to switch tabs
Problem
Submissions

Problem: Number of Valid Words for Each Puzzle

Try to solve the Number of Valid Words for Each Puzzle problem.

Statement

You are given an array of strings words and an array of strings puzzles.

A string word is considered valid with respect to a string puzzle if both of the following conditions are satisfied:

  • word contains the first letter of puzzle.

  • Every character present in word is also present in puzzle.

Return an array answer where answer[i] is the number of words in words that are valid with respect to puzzles[i].

Constraints:

  • 1≤1 \leq words.length ≤105\leq 10^5

  • 4≤4 \leq words[i].length ≤50\leq 50

  • 1≤1 \leq puzzles.length ≤104\leq 10^4

  • puzzles[i].length =7= 7

  • words[i] and puzzles[i] consist of lowercase English letters.

  • Each puzzles[i] does not contain repeated characters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Valid Words for Each Puzzle

Try to solve the Number of Valid Words for Each Puzzle problem.

Statement

You are given an array of strings words and an array of strings puzzles.

A string word is considered valid with respect to a string puzzle if both of the following conditions are satisfied:

  • word contains the first letter of puzzle.

  • Every character present in word is also present in puzzle.

Return an array answer where answer[i] is the number of words in words that are valid with respect to puzzles[i].

Constraints:

  • 1≤1 \leq words.length ≤105\leq 10^5

  • 4≤4 \leq words[i].length ≤50\leq 50

  • 1≤1 \leq puzzles.length ≤104\leq 10^4

  • puzzles[i].length =7= 7

  • words[i] and puzzles[i] consist of lowercase English letters.

  • Each puzzles[i] does not contain repeated characters.