Cheapest product in each category
Given `products` with columns `sku`, `category`, `price` and `stock`, return the single cheapest product per category, breaking ties by `sku` ascending. Return `category`, `sku` and `price`, sorted by `category` ascending.
Implement
cheapest_per_category(products: dataframe) → dataframeExamples
in
[{"__df__":[{"sku":"A-1","price":9.99,"stock":12,"category":"tools"},{"sku":"B-2","price":24.5,"stock":0,"category":"tools"},{"sku":"C-3","price":15,"stock":7,"category":"garden"},{"sku":"D-4","price":15,"stock":3,"category":"garden"},{"sku":"E-5","price":42,"stock":0,"category":"kitchen"}]}]out[{"sku":"C-3","price":15,"category":"garden"},{"sku":"E-5","price":42,"category":"kitchen"},{"sku":"A-1","price":9.99,"category":"tools"}]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 9 min
solution.py
InputExpectedGot
[{"__df__":[{"sku":"A-1","price":9.99,"stock":12,"category":"tools"},{"sku":"B-2","price":24.5,"stock":0,"category":"tools"},{"sku":"C-3","price":15,"stock":7,"category":"garden"},{"sku":"D-4","price":15,"stock":3,"category":"garden"},{"sku":"E-5","price":42,"stock":0,"category":"kitchen"}]}][{"sku":"C-3","price":15,"category":"garden"},{"sku":"E-5","price":42,"category":"kitchen"},{"sku":"A-1","price":9.99,"category":"tools"}]not run yetsample