1

Harmonic Mean

Unsolved
Prob. and Stats

Difficulty: 2 | Problem written by Sakar Ghimire
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

Harmonic Mean (also known as Contrary Mean) is one of several kinds of averages. Harmonic Mean is used when average of rates is required. The formula for calculating harmonic mean is : 

\(HM = {n \over (({1\over x_1})+ ({1 \over x_2})...+({1\over x_n}))}\)

For a given array (list of numbers), calculate and return the harmonic mean.  

Sample Input:
<class 'list'>
arr: [5, 7, 4, 4, 6, 2, 8]

Expected Output:
<class 'float'>
4.282592862345229

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Nesciunt quis incidunt eum expedita commodi iusto cumque libero? Maxime corrupti temporibus soluta error possimus quibusdam odit facere enim.

Praesentium quis ad voluptatibus mollitia, dolorem unde eos laudantium nemo odit accusantium? Quibusdam dolor aperiam repellendus nostrum, delectus neque labore at? Obcaecati soluta quasi nemo cupiditate et, debitis cum hic temporibus fuga reprehenderit sit quas architecto corporis facilis repellat, atque iusto aliquam fugiat quibusdam unde mollitia quisquam, cum officia nam.

In ullam minus voluptate accusamus reiciendis tenetur alias culpa, optio ea impedit nemo, voluptatum officia ducimus debitis in molestias reprehenderit obcaecati illo, consectetur odio atque doloremque suscipit ipsam similique ad sunt fugit, vero reprehenderit eaque accusantium placeat eum? Minima rerum aliquam ipsum corporis iste repellendus voluptas quidem. Magnam omnis consequuntur illo ad provident doloremque exercitationem sit expedita est, odio facere id repellat modi cumque, similique minima aut, voluptates totam enim commodi corrupti. Id odit rerum quo saepe accusantium enim beatae eligendi dicta ipsa repellat, repellendus nesciunt soluta quasi voluptatum nobis rerum cum facilis omnis, amet quidem architecto dignissimos vel.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)