Code RoomFind shard boundary
EasyPrep Room Coding #4805

Find shard boundary

CodingAlgorithms & data structuresEntry–Mid~15 min

A key value store spreads its keyspace over shards and routes every request through a boundary table. boundaries is sorted ascending and holds no repeats, and boundaries[i] is the first key belonging to shard i + 1. Shard 0 therefore holds every key ordered before boundaries[0], a middle shard holds the keys from its own boundary up to but not including the next one, and the last shard holds every key at or after the final boundary. A key equal to a boundary belongs to the shard that boundary opens, the higher of the two. Keys compare as ordinary text, character by character, so capitals come before lowercase. Return the shard index for each entry of keys, in the order given. A table with no boundaries means a single shard, so every key routes to 0, and an empty key list returns an empty list. The table is consulted on every request, so halve it rather than scan it.

Implement
route_keys_to_shards(boundaries: list[str], keys: list[str]) → list[int]
Examples
in[["dana","mira","tomas"],["alice","dana","evan","mira","zoe","tomas"]]out[0,1,1,2,3,3]
in[["dana","mira","tomas"],["Zed","mir","mirabel","tomas"]]out[0,1,2,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 15 min
InputExpectedGot
[["dana","mira","tomas"],["alice","dana","evan","mira","zoe","tomas"]][0,1,1,2,3,3]not run yetsample
[["dana","mira","tomas"],["Zed","mir","mirabel","tomas"]][0,1,2,3]not run yetsample