Lexicographically smallest valid code
A batch printer stamps a code on every carton. A code is exactly code_length characters long and every character comes from wheel, whose entries are single characters, all different, listed in the order the print wheel carries them, which need not be alphabetical. blocked lists sequences the plant reserves for internal markings, and a code is invalid when any blocked sequence appears inside it as consecutive characters. A blocked sequence is one character or longer, and it may hold characters the wheel does not carry. Return the smallest valid code, where one code is smaller than another when at the first position they differ its character sits earlier on the wheel. Return an empty string when no valid code exists and when the wheel is empty. code_length is at least 1 and at most 10, and the wheel carries at most 6 characters.
smallest_safe_code(wheel: list[str], code_length: int, blocked: list[str]) → str[["a","b"],3,["aa","ab"]]out"bba"[["z","a"],2,[]]out"zz"[["a","b","c"],1,["a","b"]]out"c"State 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.
[["a","b"],3,["aa","ab"]]"bba"not run yetsample[["z","a"],2,[]]"zz"not run yetsample[["a","b","c"],1,["a","b"]]"c"not run yetsample