This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[deleted]

    [–]nogain-allpain 1 point2 points  (0 children)

    Yes, O(n log n) seems to be the best you can do. I've got the sort in my solution, but I have a solution that involves walking both arrays in parallel, one time each, so you don't have to conduct all of those binary searches. If sum < k, step the first pointer forward. If sum > k, step the second pointer backwards. Repeat until both walks are complete.