A blogging app shows how many posts use tags that start with what the author is typing. Each time a post is tagged, the tag is added once, so the same tag can be added many times.
Write a class TagPrefixCounter with:
constructor(): starts empty.add(tag): records one use of tag (a non-empty lowercase string). Returns nothing.countPrefix(prefix): returns how many recorded uses have a tag that starts with prefix. Every tag starts with the empty prefix "".Each example lists the calls in order, then each call's arguments. The first call creates the object with new TagPrefixCounter(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["TagPrefixCounter","add","add","add","countPrefix","countPrefix"] [[],["react"],["redux"],["vue"],["re"],["red"]] Output: [null,null,null,null,2,1]
react and redux start with re; only redux starts with red.
Input: ["TagPrefixCounter","add","add","countPrefix","countPrefix"] [[],["css"],["css"],["css"],["cssx"]] Output: [null,null,null,2,0]
The same tag was added twice, so both uses count. Nothing starts with cssx.
1 <= tag.length <= 300 <= prefix.length <= 3010^4 calls.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #366 Tag Prefix Counter. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.