Chief Hopper Discussions | Algorithms | HackerRank
  • + 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