A command palette lets power users type patterns where . stands for any single letter, so s.ve matches save. You need a store of command names that answers whether a pattern matches some whole command.
Write a class CommandIndex with:
constructor(): starts empty.add(name): stores the command name (lowercase letters). Returns nothing.matches(pattern): returns true if some stored name has the same length as pattern and agrees with it at every position, where . agrees with any letter.Each example lists the calls in order, then each call's arguments. The first call creates the object with new CommandIndex(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["CommandIndex","add","add","matches","matches","matches"] [[],["save"],["open"],["s.ve"],["o..n"],["sav"]] Output: [null,null,null,true,true,false]
s.ve matches save and o..n matches open; sav is too short to match a whole name.
Input: ["CommandIndex","add","matches","matches"] [[],["copy"],["...."],["....."]] Output: [null,null,true,false]
Four dots match any four-letter name.
1 <= name.length, pattern.length <= 255 dots.10^5 calls.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #370 Wildcard Command Search. 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.