STROPR - Feb 16 Long - WA

Problem

Editorial

I was trying to solve this problem by referring to the editorial, but i am getting WA for the following code.

My Code

Can anyone please find what mistake I am doing here.

//