Here i have come up with this solution…
But it is showing tle for 2 test cases…
Not able to get any new idea… Please help to improve the logic.
Showing tle for two test cases
I think you have used more brain than required. You have created too many if else cases I dont think that is required.
Here is my code. Hope it helps!!