We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 10 Days of Statistics
  4. Day 1: Standard Deviation

Day 1: Standard Deviation

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Objective
In this challenge, we practice calculating standard deviation. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given an array, , of integers, calculate and print the standard deviation. Your answer should be in decimal form, rounded to a scale of decimal place (i.e., format). An error margin of will be tolerated for the standard deviation.

Example

The sum of the array values is and there are elements. The mean is .
Subtract the mean from each element, square each result, and take their sum.





Their sum is 18. Take the square root of to get , the standard deviation.

Function Description

Complete the stdDev function in the editor below.

stdDev has the following parameters:
- int arr[n]: an array of integers

Prints
- float: the standard deviation to 1 place after the decimal

Input Format

The first line contains an integer, , denoting the size of arr.
The second line contains space-separated integers that describe .

Constraints

Output Format

Print the standard deviation on a new line, rounded to a scale of decimal place (i.e., format).

Sample Input

STDIN           Function
-----           --------
5               arr[] size n = 5
10 40 30 50 20  arr =[10, 40, 30, 50, 20]

Sample Output

14.1

Explanation

First, find the mean:

Next, calculate the squared distance from the mean, , for each :

Now compute , so:

Author

AvmnuSng

Difficulty

Easy

Max Score

30

Submitted By

54084

Need Help?


View tutorial
View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy