Code RoomSplit SKU into letter number
MediumPrep Room Coding #5136

Split SKU into letter number

CodingAlgorithms & data structuresMid–Senior~10 min

Given `products` with columns `sku`, `category`, `price` and `stock`, where every `sku` looks like `A-1`, split it on the hyphen into `letter` and `number`, keeping `number` as a string. Return `sku`, `letter` and `number`, sorted by `sku` ascending.

Implement
split_sku(products: dataframe) → dataframe
Examples
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","letter":"A","number":"1"},{"sku":"B-2","letter":"B","number":"2"},{"sku":"C-3","letter":"C","number":"3"},{"sku":"D-4","letter":"D","number":"4"},{"sku":"E-5","letter":"E","number":"5"}]
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 10 min
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","letter":"A","number":"1"},{"sku":"B-2","letter":"B","number":"2"},{"sku":"C-3","letter":"C","number":"3"},{"sku":"D-4","letter":"D","number":"4"},{"sku":"E-5","letter":"E","number":"5"}]not run yetsample