Suppose we create a list of array and runs a loop and check if(l.contains(sum-l.get(i))) then print the both the number else continue
Can we approach this way
Yes, you definitely can do it this way but it should give TLE. That’s because contains function itself is O(n) and running that for every element, the complexity becoomes n squared.