Difficulty: Easy Tags: Classic ML, Data Processing
Instacart's substitution-suggestion model needs the categorical product-department column encoded before it can touch a single row of cart data. This is the same mechanic as the Airbnb amenity question, different domain, because this exact operation shows up constantly across real pipelines.
One-hot encode a categorical column into an n x k binary matrix, k the number of distinct
categories, columns alphabetical.
n
dept_1
...
dept_n
First line: distinct departments alphabetically. Next n lines: one-hot rows.
1 <= n <= 10^4Input
4
dairy
produce
dairy
bakery
Output
bakery dairy produce
0 1 0
0 0 1
0 1 0
1 0 0
No results yet
Run your code to check it against the examples, or submit to run every test.