Closest Sum in an Array

You are given an array of integers and a target integer K as arguments. Return an array of two integers from the original array, that when added together is closest to K.

No two integers will sum up to be exactly K.

Requirements

  • Must return an array of integers

Example #1

solve([1, 5, 15, 20], 22)
> [1, 20]

The sum of 1 and 20 is 21, which is closest to 22

Example #2

solve([-10, 17, 15, 25], 4)
> [-10, 15]

The sum of -10 and 15 is 5, which is closest to 4