Bin code prefix length
A warehouse terminal lets a picker type a bin code and stops asking for more characters the moment what they have typed can only be one bin. Given codes, return a list where element i is the length of the shortest prefix of codes[i] that is not also a prefix of any other code in the list. A prefix is at least one character long, and a code counts as a prefix of itself, so when the whole of codes[i] is the opening stretch of some other code nothing types it out on its own: return 0 for that entry. Two identical codes therefore both answer 0, and so does an empty code. Comparison is exact and case sensitive. Return one answer per code, in the order the codes are given.
bin_code_prefix_lengths(codes: list[str]) → list[int][["dock","dorm","east"]]out[3,3,1][["ab","abc"]]out[0,3][["cold-store","cold-room","cool-room"]]out[6,6,3]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.
[["dock","dorm","east"]][3,3,1]not run yetsample[["ab","abc"]][0,3]not run yetsample[["cold-store","cold-room","cool-room"]][6,6,3]not run yetsample