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.
Let b_i be the price written on the ith ball. Let X_i be a random variable such that X_i = b_i if the ith coin toss is heads and X_i = 0 otherwise. The expected value of X_i is E(X_i) = b_i / 2. Let X = X_1 + ... + X_n. The price of the phone is E(X) = E(X_1) + ... + E(X_n) = (b_1 + ... + b_n) / 2.
Python code:
return.5*sum(balls)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
B'day Gift
You are viewing a single comment's thread. Return to all comments →
Let b_i be the price written on the ith ball. Let X_i be a random variable such that X_i = b_i if the ith coin toss is heads and X_i = 0 otherwise. The expected value of X_i is E(X_i) = b_i / 2. Let X = X_1 + ... + X_n. The price of the phone is E(X) = E(X_1) + ... + E(X_n) = (b_1 + ... + b_n) / 2.
Python code: