Given a list of integers,
l = [1,5,3,2,6]
and a targett = 6
, return true if the list contains two distinct integers that sum to the target
I was given this question on a technical Python interview that caused me not to pass. My answer was:
def two_Sum(l, target):
for num in l:
for secondNum in l:
if num != secondNum:
if num + secondNum == target:
return True
The feedback I was given was that my solution was "not optimal". Please help me to understand why this was not the optimal solution and explain in detail what would be optimal for this case!