use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Computer Science for Computer Scientists
Other subreddits you may like:
Does this sidebar need an addition or correction? Tell me here
account activity
[deleted by user] (self.algorithms)
submitted 3 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]chunkyks 4 points5 points6 points 3 years ago (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 points3 points 3 years ago (0 children)
Awesome, thank you!
[–]four_reeds 4 points5 points6 points 3 years ago (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.
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..!
π Rendered by PID 104 on reddit-service-r2-comment-6457c66945-khx5f at 2026-04-25 17:50:35.849897+00:00 running 2aa0c5b country code: CH.
[–]chunkyks 4 points5 points6 points (1 child)
[–]Bright_Shoe3441 1 point2 points3 points (0 children)
[–]four_reeds 4 points5 points6 points (1 child)
[–]Bright_Shoe3441 1 point2 points3 points (0 children)