Python Discussion Forums

There's no such thing as a stupid question. Ask. Discuss. Learn.

Cant get my head round the algorithm

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

Mikiko Anhoco 6 months ago
  • Charl Boyle

    Have the same issue dont know how to wrap my head arround either.


  • It's been a lot harder than I thought I would be to find an example of the technologies python devs use in their day-to-day. I know you, obviously, use Python and Django/Flask, probably MySQL too, but can anyone share what a solid stack would be? I tried looking at some job listings to get an idea but they seem all over the place, including front-end frameworks like Angular and stuff that doesn't really belong on the back end.


  • 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. https://discord.software/ https://vshare.onl/

    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
    my issue got solved!!


  • Whitelisted Links