Apr-09-2019, 10:29 PM
Hi all.
Wonder anyone here can help to get the algorithm right. I have sorted list of numbers and I need to pair of numbers which add to target or close to target. For instance
List 500 700 1000 1400 2000
target 2300
There inst a direct match but the closest is 1400 + 700 which gives me 2100. And this the right answer.
I've tried the traditional approach were using dynamic programming you the find difference between the current position and the target and look to find the difference number existing in the hash. This works well for a direct match but not for the closet match.
I wonder if there is a better way to doing this?
Any pointers are much appreciated.
Many thanks
Wonder anyone here can help to get the algorithm right. I have sorted list of numbers and I need to pair of numbers which add to target or close to target. For instance
List 500 700 1000 1400 2000
target 2300
There inst a direct match but the closest is 1400 + 700 which gives me 2100. And this the right answer.
I've tried the traditional approach were using dynamic programming you the find difference between the current position and the target and look to find the difference number existing in the hash. This works well for a direct match but not for the closet match.
I wonder if there is a better way to doing this?
Any pointers are much appreciated.
Many thanks