make the full circular path, shortest path exercise?

后端 未结 8 1512
耶瑟儿~
耶瑟儿~ 2021-02-04 22:27

I got this question in an interview and I was not able to solve it.

You have a circular road, with N number of gas stations. You know the ammount of gas

8条回答
  •  感情败类
    2021-02-04 23:11

    The task is really open. As you do a cycle, so the best option is to start from the station that have largest enough fuel amount. This mean that you will be able to tank your car and drive to next nearest station.

    When we have a place to start we only have to decide on which gas station we need to stop. For the first run we can stop an every station.

    EDIT.

    Small improvement that came up after discussion with Lasse V. Karlsen.

    If the selected first station will not succeed to make the cycle. Then select next one in the same way with smaller* fuel/road proportion.

    *Smaller then first selected station proportion.

提交回复
热议问题