Solutions considering duplicates in the array.

The existing solution was ignoring the duplicates in the array.
For example: 
f(8, [3, 4, 5, 4, 4]) //Output: [ [3, 5], [4, 4]]

No changes have to made to the existing methods. But two new methods have been added which take duplicates into consideration.
For Example:
f(8, [3, 4, 5, 4, 4]) //Output: [ [3, 5], [4, 4], [4, 4], [4, 4]]