How should i approach this problem

i tried solving it but even though is got the right output; it didnt satisfy any of the test cases.

here is the link of what i did:

hi @priyanshu180901_fb9ce5685f941d19,
refer
ive commented the code