Code RoomBin code prefix length
EasyPrep Room Coding #4840

Bin code prefix length

CodingAlgorithms & data structuresEntry–Mid~16 min

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.

Implement
bin_code_prefix_lengths(codes: list[str]) → list[int]
Examples
in[["dock","dorm","east"]]out[3,3,1]
in[["ab","abc"]]out[0,3]
in[["cold-store","cold-room","cool-room"]]out[6,6,3]
What a strong answer looks like

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.

0:00 of about 16 min
InputExpectedGot
[["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