DataLane

9. Min-max normalize

hardProNot started~10 minPythonImplement normalize()

Asked in screens shaped like: Google, Databricks

Scale x into [0, 1] with (x - min) / (max - min). If every value is equal, return zeros. Return a list of floats rounded to 4 decimals.

Examples

  • Example 1

    Input: { "x": [0, 5, 10] }
    Output: [0, 0.5, 1]

Constraints

  • 1 <= n <= 10**5, where n is the length of the input
  • Input is non-empty

Python editor

Loading Python engine…

Ctrl/Cmd + Enter submits

Run your code to see stdout.

Pro problem

Hard problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close