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
2
Q
A