Cheapest stock items
Your task
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.
Examples
pick_cheapest_substitutes(skus: list[str], cents: list[int], in_stock: list[bool], k: int) -> list[str]pick_cheapest_substitutes(["SKU-9", "SKU-10", "SKU-3"], [500, 500, 450], [True, True, True], 2)["SKU-3", "SKU-10"]pick_cheapest_substitutes(["OAT-1", "SOY-2", "ALM-3", "RIC-4"], [320, 280, 280, 199], [True, False, True, True], 3)["RIC-4", "ALM-3", "OAT-1"]pick_cheapest_substitutes(["A", "B", "C"], [10, 20, 30], [False, True, True], 1)["B"]