can anyone please tell what’s wrong with my code?
BUILDB or CM164364? Your linked solution is for the latter
Brother your linked solution is of other problem
The entire code is right, but you need to make slight changes at the end, in the if else part.
For these test case your code is giving wrong results. Try to patch the bug or else you can go through the below link, I’ve submitted your code by making necessary corrections.