3 sum Zero - interviewbit

i wrote the code using 2 pointers approach. tests cases are passing but when submitting getting TLE. Help me improve the code.

ide->https://ide.codingblocks.com/s/242032

ques->https://www.interviewbit.com/problems/3-sum-zero/

@mikkyimran
Hello mohd imran, time complexity of your code is O(N^2) since you are apply two pointer over whole array for each i. To reduce time what you can do is first sort the array, And then you can take two pointer starting from first and last index and binary search over remaining array to find 3rd element. This will reduce time to O(nlogn)

@mikkyimran
Please mark this doubt as resolved. If you have no more doubt regarding this question.

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.