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.
- Prepare
- Algorithms
- Greedy
- Chief Hopper
- Discussions
Chief Hopper
Chief Hopper
+ 0 comments Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Chief Hopper Problem Solution
+ 1 comment C++
int chiefHopper(vector<int> h) { int n = h.size(); int end = 0; int tem = 0; for (int i = n - 1; i >= 0; i--) { tem = end + h[i]; if (tem % 2 == 0) end = tem / 2; else end = tem / 2 + 1; } return end; }
+ 0 comments Python 3. The idea is to work backwards assuming that the final energy must be 0 or 1.
def chiefHopper(arr): e=0 for h in arr[::-1]: e=(e+h+1)//2 return e
+ 0 comments Here is the solution of Chief Hopper Click Here
+ 1 comment I have a one question with Python3. I use formula "e_0 \geq {\sum^{i}_{j=1}2^{i-j}*h_j\over{2^i}}" from e_i = 2^{i}*e_0 - \sum^{i}_{j=1}2^{i-j}*h_j
When I try to submit my code, only one case is failed and I found it 99999+(99999/(2^1000)) == 99999. I want to why it works like this and how to solve this problem.
Here is my python3 code:
def chiefHopper(arr): # Write your code here min_energy = 0.0 for i in range(len(arr)): min_energy += arr[i]/(2**(i+1)) return math.ceil(min_energy)
Load more conversations
Sort 145 Discussions, By:
Please Login in order to post a comment