Step 3 of 4
Prefix Matching (startsWith)
You start from the build so far — your own work where you have written it, the reference build where you have not. Either way this step stands on its own.
Implement startsWith(prefix) to determine whether any word in the Trie begins with the given prefix.
- Walk the path for each character in
prefix. - If all character nodes exist, return
trueimmediately (the final node does not need to haveisEndOfWordset). - If any character node is missing, return
false.
Your build
Running is free — Submit is what records the step. Or press ⌘↩
Tests
1 case| call | type | expected | result |
|---|---|---|---|
| runOps([["insert","banana"],["insert","band"],["startsWith","ban"],["startsWith","band"],["startsWith","bar"]]) | verifies prefix existence without complete word requirement | [null,null,true,true,false] | — |
Hints
Stuck? Hints open one at a time, each giving a little more away.
2 hints left