Question regarding WALKFAST

Question link: CodeChef: Practical coding for everyone

Answer link: CodeChef: Practical coding for everyone

Can anyone help me figure out the problem in my code?

[simon@simon-laptop][15:35:59]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling prakashaditya-WALKFAST.cpp
+ g++ -std=c++14 prakashaditya-WALKFAST.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
+ set +x
Successful
[simon@simon-laptop][15:36:07]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt
1
5 5 3 4 2 58 72 72
-65 -64 -61 -29 92
[simon@simon-laptop][15:36:10]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt | ./a.out 
prakashaditya-WALKFAST.cpp:17:43: runtime error: index 5 out of bounds for type 'long int [*]'
prakashaditya-WALKFAST.cpp:18:40: runtime error: index 5 out of bounds for type 'long int [*]'
5485150466141248

Edit:

Actually, your solution has out-of-bounds accesses for the sample test input, too.

1 Like