This is task from my trainee interview. I haven't found the answer yet and hope you can help me. (Interview was about 2 weeks ago and I failed). So - you got robot-drone with wheels. You recieve photo from space which converts to matrix with heights above sea level (every element is square 100*100 meters). For example:
3 2 1 0 1 2 3
3 2 1 0 1 2 3
3 2 1 0 1 2 3
3 2 1 0 1 2 3
//thats the road between 2 mountains ( 0 0 0 0 - road, 1 higher, 2 higher and so on)
rules: every move costs 1 point of fuel, but ascent or descent - costs difference between heights. For example if you go from 4 to 2 - it would be (4-2 + 1 (every step costs one)) = 3 You need to find the shortest path from top left point to bottom right point. AND I KNOW HOW TO DO IT. We can use Dijkstra algorithm and everything works fine.
But the hardest point in the task - each diagonal move costs twice as much as the previous one. So first diagonal move costs 1, second 2, third 4, forth 8 and so on. I don't know how create this rule and how combine it with Dijkstra algorithm, to make look it simple and work fine.
If you have solution - please share it.
i just read a book on algorithms and it didn't help me(
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment