Whats wrong why time limit exceed?
@gagz23 try here
https://hack.codingblocks.com/app/contests/1511/1090/problem
, it passes all tests https://ide.codingblocks.com/s/321692
but your actual algorithm complexity is O(n^2) (because of insertion), try making it O(n)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.