Trie prefix match length
A documentation site holds every searchable term in a prefix tree, so the suggestion list is found by walking down from the root one typed character at a time. The list narrows with each keystroke and goes empty the moment a character has no branch to follow. The support team wants to know where a visitor's query left the tree. You get indexed_terms, the stored terms, and typed, what the visitor entered. Return the largest count of leading characters of typed that still match, meaning the largest k between 0 and the length of typed for which at least one indexed term begins with the first k characters of typed. Return 0 when the very first character already matches nothing, when typed is empty, or when the index holds no terms. Indexed terms are non empty and matching is case sensitive.
typeahead_match_depth(indexed_terms: list[str], typed: str) → int[["config","connect","console"],"conf"]out4[["config","connect","console"],"connx"]out4[["go"],"gopher"]out2State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["config","connect","console"],"conf"]4not run yetsample[["config","connect","console"],"connx"]4not run yetsample[["go"],"gopher"]2not run yetsample