Help needed in MSTICK (DSA Learning Series)

Can someone help with Matchsticks problem? I am facing difficulty in the implementation part of the segment tree. I tried to follow from GeeksForGeeks and my code is clearing all sample test cases, but when submitting it’s giving me a wrong answer.

Can someone help me find out what’s wrong with my code? I have tried to use as many comments as possible.

CodeChef: Practical coding for everyone .Thank You :slightly_smiling_face: