Loading
Loading
A search box shows, as the user types, how many catalogue entries begin with what they have typed so far. The catalogue is fixed; the typed prefixes arrive as a batch to answer.
Given words and prefixes, return an array whose i-th value is the number of words that begin with prefixes[i]. A word counts as beginning with itself, and repeated words count each time they appear.
words = ["cart", "care", "cat", "dog"], prefixes = ["ca", "car", "d", "x"]c → athree words pass through this nodec → a → rtwo words pass throughdone wordxno such child: zero[3, 2, 1, 0]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(total characters) time · O(total characters) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
ca matches cart, care and cat; car matches cart and care; d matches dog; x matches nothing.
Example 2
Repeated words count each time they appear.