PREP27 Editorial

Problem Explanation

In this problem we have to find all unique groups of 4 numbers in an array which add up to a given number.

Approach

We first sort the array to easily skip over duplicate values and easily search for TwoSum(Two numbers in a given range that add up to a given value). We then iterate over all the pairs in the array, fix them as the first two elements in the quadruple. And iterate over the rest of the elements to find the TwoSum for the remaining value.

After considering every value we skip over the duplicates.