The Normalizer
You are preprocessing training data for a machine learning model. Raw feature values come in wildly different ranges — some in the thousands, some negative. Before feeding data to the model, you must normalize each feature to the range [0, 1] using min-max scaling.
Given a 1D array of integers, return a new array where each value is normalized using:
normalized[i] = (x[i] - min(x)) / (max(x) - min(x))
Round each output value to 6 decimal places. Return the result as a Python list.
Example 1
[-10, 0, 10, 20, 30][0.0, 0.25, 0.5, 0.75, 1.0]Range is 40. Each value normalized: (-10-(-10))/40=0.0, (0-(-10))/40=0.25, etc.
Example 2
[-500, -250, -100][0.0, 0.625, 1.0]Range is 400. (-250-(-500))/400 = 250/400 = 0.625.
Example 3
[1000, 500, 0, -500][1.0, 0.666667, 0.333333, 0.0]Reverse sorted — largest value maps to 1.0, smallest to 0.0.
- ›2 <= len(arr) <= 1000
- ›All values are integers in range [-1000, 1000]
- ›max(arr) != min(arr) — not all values are equal
Reference solution available after you attempt the question.
Ready to solve it?
Start a session on Mockbit #65. Write your code, run it against hidden tests, and get graded with specific critique on each axis.