Code RoomCheapest stock items
EasyPrep Room Coding #4770

Cheapest stock items

CodingDistributed systemsAlgorithms & data structuresEntry–Mid~13 min

A grocery app offers replacements when a shopper's item is unavailable. skus holds the candidate product codes, cents holds each candidate's shelf price in cents, in_stock says whether the warehouse can actually pick that candidate, and the three lists are the same length. Return the product codes of the k cheapest candidates the warehouse can pick, cheapest first. Candidates that are not in stock are dropped before anything is chosen, so k counts only pickable ones. Two candidates on the same price are ordered by product code ascending as ordinary strings, compared character by character, so SKU-10 comes before SKU-9. Product codes are distinct. When fewer than k candidates survive the stock filter, return every survivor in that order, and when k is zero or negative return an empty list.

Implement
pick_cheapest_substitutes(skus: list[str], cents: list[int], in_stock: list[bool], k: int) → list[str]
Examples
in[["SKU-9","SKU-10","SKU-3"],[500,500,450],[true,true,true],2]out["SKU-3","SKU-10"]
in[["OAT-1","SOY-2","ALM-3","RIC-4"],[320,280,280,199],[true,false,true,true],3]out["RIC-4","ALM-3","OAT-1"]
in[["A","B","C"],[10,20,30],[false,true,true],1]out["B"]
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 13 min
InputExpectedGot
[["SKU-9","SKU-10","SKU-3"],[500,500,450],[true,true,true],2]["SKU-3","SKU-10"]not run yetsample
[["OAT-1","SOY-2","ALM-3","RIC-4"],[320,280,280,199],[true,false,true,true],3]["RIC-4","ALM-3","OAT-1"]not run yetsample
[["A","B","C"],[10,20,30],[false,true,true],1]["B"]not run yetsample