Difficulty: Easy Tags: Data Processing, Classic ML
Every Airbnb listing carries a categorical amenities tag, and the pricing model cannot consume raw strings. This is the encoding step that runs before every single downstream feature touches the model.
One-hot encode a categorical column of n values into an n x k binary matrix, where k is the
number of distinct categories present, columns ordered alphabetically.
n
cat_1
cat_2
...
cat_n
First line: the k distinct categories, alphabetically, space-separated. Next n lines: the
one-hot row for each input, space-separated 0/1.
1 <= n <= 10^4, category strings up to 20 charactersInput
5
wifi
parking
wifi
pool
parking
Output
parking pool wifi
0 0 1
1 0 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.