Node.js needs more time limit

My solution for this problem gets TLE.
https://www.codechef.com/viewsolution/1018869979

But the same solutions in other languages got accepted. For example:
https://www.codechef.com/viewsolution/1018869412
https://www.codechef.com/viewsolution/1018864337

No. They are not the same algorithms. splice() that you have used is O(n) in NodeJS. The intended solution is to not use a simple array but a balanced binary search tree-type data structure to do it in O(log(n)) time.

1 Like

Are you telling me that pop() a random element (not the last) from array in python is not O(n)? Because I have links saying otherwise. And yet it was accepted.

And from what i have read about binary search trees, they would still use O(n) time if you add elements in already sorted order. So one custom test case would fail all your intended solutions.

You might want to read up on Balanced Binary Search Trees. Not just a simple BST.