Chief Hopper Discussions | Algorithms | HackerRank
  • + 1 comment

    Integer overflow. Even long long would not be enough to hold values for 'energy' with your current logic so it overflows and becomes negative. Because of this "while" stops too early (as energy is not >= 0). If you won't come up with idea how to overcome that, feel free to ask for clue.