Products still in stock
Given `products` with columns `sku`, `category`, `price` and `stock`, return the products whose `stock` is greater than zero. Return only `sku` and `price`, sorted by `price` ascending and then `sku` ascending.
Implement
in_stock(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":"A-1","price":9.99},{"sku":"C-3","price":15},{"sku":"D-4","price":15}]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 7 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":"A-1","price":9.99},{"sku":"C-3","price":15},{"sku":"D-4","price":15}]not run yetsample