I have An array . I want pairs such that their sum is closest to 54. I know how to solve it. But solution that i know is taking O(N^2) time complexity. is there a way to get sum of all value pairs in O(N) in javascript?
let arr = [20 , 30, 18, 40 , 22]
const x = 54
output (30,22)