i wrote the code using 2 pointers approach. tests cases are passing but when submitting getting TLE. Help me improve the code.
3 sum Zero - interviewbit
@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)
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.