Trains the technique from
LeetCode 1268Search Suggestions SystemThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A stores terminal holds codes, the part codes it stocks, all of them different and written in lowercase letters. A clerk looks a part up by typing typed one letter at a time, left to right.
After each letter the terminal offers hints: the part codes that begin with everything typed so far. At most three are offered, and when more than three codes qualify the terminal offers the three that come first in dictionary order. The hints in a single offer are listed in dictionary order too, and an offer with no qualifying code is empty.
Return one list of hints per letter typed, in the order the letters were typed, so the result holds exactly typed.length lists.
Example 1
After "b" four codes qualify, so the first three in dictionary order are offered. After "bo" the qualifying codes are "bo", "bolt" and "boltcap". After "bol" only "bolt" and "boltcap" qualify.
Example 2
The single code qualifies for "n", "nu" and "nut", and nothing in the catalogue begins with "nuts", so the last offer is empty.
Example 3
After "w" all three codes qualify and are listed in dictionary order. After "we" the code "washer" no longer qualifies.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def prefix_hints(codes: list[str], typed: str) -> list[list[str]]:public List<List<String>> prefixHints(String[] codes, String typed)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.