Trie prefix match length

Write codeEasy14 minGoogle style

Your task

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.

Examples

typeahead_match_depth(indexed_terms: list[str], typed: str) -> int
Example 1
Inputtypeahead_match_depth(["config", "connect", "console"], "conf")
Output4
Example 2
Inputtypeahead_match_depth(["config", "connect", "console"], "connx")
Output4
Example 3
Inputtypeahead_match_depth(["go"], "gopher")
Output2