Hello everyone, I was trying to solve this question : Link using the approach discussed here. I have understood the approach to the problem but My code is unable to pass the time limit. Can someone please help me optimize it? I have tried to optimize it but to no avail. Any kind of help will be appreciated.
Link to my submission : Code







