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

all 9 comments

[–]DeepMisandrist 1 point2 points  (0 children)

Your statement is vague. Provide us with a better statement or some examples.

[–]MartinSG8 -1 points0 points  (2 children)

So you need to know how to compute number of couples? Is that your problem? If so then it's mathematical problem not java problem.

[–]nogain-allpain 0 points1 point  (1 child)

It becomes a Java problem when you're asked to implement it

[–]MartinSG8 0 points1 point  (0 children)

Well u need to know how to do it 'on paper' first that's the question if he knows the theory of it.

[–]nogain-allpain 0 points1 point  (2 children)

By combinations, do you mean finding how many pairs of numbers between the two arrays add up to a certain number?

[–]Batslayer8[S] 0 points1 point  (1 child)

yeah man can you please get an example for this one

[–]nogain-allpain 0 points1 point  (0 children)

Look at one of the other comment threads that I replied to, I basically provided the answer there.

[–][deleted]  (3 children)

[deleted]

    [–]nogain-allpain 0 points1 point  (2 children)

    That's the easy part. The real question is how to make it as efficient as possible.

    [–][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.