Z-Score Normalize

MediumStatisticsMathArray

Description

Given a non-constant array nums, return the array of z-scores (each value minus the mean, divided by the population standard deviation), each rounded to 4 decimal places.

Examples

Input:nums = [1,2,3,4,5]
Output:[-1.4142,-0.7071,0,0.7071,1.4142]
Explanation:

Centering each value and scaling by the population standard deviation gives [-1.4142,-0.7071,0,0.7071,1.4142].

Input:nums = [10,20,30]
Output:[-1.2247,0,1.2247]
Explanation:

Centering each value and scaling by the population standard deviation gives [-1.2247,0,1.2247].

Input:nums = [2,4,4,4,5,5,7,9]
Output:[-1.5,-0.5,-0.5,-0.5,0,0,1,2]
Explanation:

Centering each value and scaling by the population standard deviation gives [-1.5,-0.5,-0.5,-0.5,0,0,1,2].

Constraints

  • 2 ≤ nums.length ≤ 10⁴
  • nums is not constant

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.