Chief Hopper Discussions | Algorithms | HackerRank

Sort by

recency

|

147 Discussions

|

  • + 0 comments
    def chiefHopper(arr):
        energy = 0
        for height in reversed(arr):
            energy = (energy + height + 1) // 2
        return energy
    
  • + 0 comments

    Easy Solution

     public static int chiefHopper(List<Integer> arr) {
            int E = 0;
            for (int i = arr.size() - 1; i >= 0; i--){
                E = (int) Math.ceil((E + arr.get(i)) / 2.0); 
            }
            return E;
        }
    
  • + 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