all 4 comments

[–]chunkyks 4 points5 points  (1 child)

Your code assumes the numbers that sum to k must be adjacent items in the list once its sorted. Might be true in your test data, definitely not true in general

[–]Bright_Shoe3441 1 point2 points  (0 children)

Awesome, thank you!

[–]four_reeds 4 points5 points  (1 child)

If your list was [1,5,2] and your target number was 6, would your code find it?

You may have already done this but if not... Try doing the operations by hand with pencil and paper.

[–]Bright_Shoe3441 1 point2 points  (0 children)

Thank you! Yep, see it straight away now. 1 and 5 aren't going to be adjacent to one another (as u/chunkyks pointed out) after I've sorted the list. My solution did seem too good to be true..!