Read the Pages Getting Wrong Ans for One test case

Question

Code

Why complicate things instead of keeping them simple