[Hacker Rank] Chief Hopper

Chief Hopper

  • Time : O(n)
  • Space : O(1)
1
2
3
4
5
6
7
long long chiefHopper(vector<int> arr) {
long long res = 0;
for(int i = arr.size() - 1; i >= 0; i--) {
res = ceil((res + arr[i]) / 2.0);
}
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/06/12/PS/HackerRank/chief-hopper/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.