Count Inversions Flashcards

1
Q

Three Number Sum: Find all triplets in an array that sum up to a target sum. Return a 2D Array w/ all triplet combinations.

A

Sort input array
Create output array of arrays
loop through array once (stop two before end)
set a left pointer
set a right pointer
loop while left < right
calculate current sum
if the current sum == target
add it to the output, increment left ptr / dec right ptr
else if the current sum <
increment left to make a larger sum
else if current sum >
decrement right to make a smaller sum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly