Why am I getting WA

Can someone please help me understand why I’m getting WA. I’ve passed sample test cases and I think my approach is correct. Please help me find error in my problem
Question:
https://www.codechef.com/CCRC21C/problems/CHEFPAT
My Solution:
https://www.codechef.com/viewsolution/50325278

Out of bounds access with sample input:

[simon@simon-laptop][07:02:54]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling somibb21-CHEFPAT.cpp
+ g++ -std=c++14 somibb21-CHEFPAT.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv -fno-sanitize-recover
+ set +x
Successful
[simon@simon-laptop][07:03:01]
[~/devel/hackerrank/otherpeoples]>echo "4
> 5
> 2 3 5 3 4
> 3
> 2 2 2
> 6
> 2 10 3 3 2 10
> 4
> 8 9 8 9" | ./a.out
somibb21-CHEFPAT.cpp:29:37: runtime error: index 5 out of bounds for type 'int [*]'
1 Like

I understood. Thank you

1 Like