TLE error how to coorect it

question:-https://hack.codingblocks.com/app/contests/1331/276/problem
answer:https://ide.codingblocks.com/s/265420
test case not passing showing TLE error how we correct it,plz help me out sir

hello @rajsharma96309
contruct a balanced bst to avoid tle.

constructtion of balanced bst will take O(nLOGn) time .

but urs will take O(n^2) in worst case ,thats why u r getting tle

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.