Normalize and encode tabular data

Write codeMedium30 minMeta style

Your task

Preprocess a tiny tabular dataset. You are given rows, a list of records where each record is [value, category] with value a number and category a string, and categories, the ordered list of all possible category strings. Min-max normalize the numeric column to [0,1] using v' = (v - min) / (max - min); if max == min, every normalized value is 0.0. One-hot encode the category against the categories list (a 1.0 in the position of the matching category, 0.0 elsewhere). Return a list of feature rows, where each row is [normalized_value] followed by the one-hot vector. Round every output number to 6 decimals. There is at least one row.

Examples

preprocess(rows: list[list], categories: list[str]) -> list[list[float]]
Example 1
Inputpreprocess([[10, "a"], [20, "b"], [30, "a"]], ["a", "b"])
Output[[0, 1, 0], [0.5, 0, 1], [1, 1, 0]]