Test case 5’s solution appears to be wrong. The rules said to go UP first if tied. For current floor 11, both 10 and 12 and closest to it, but the rule said to go UP first, hence the solution is wrong.
I get what you’re thinking, but the tests are looking at the difference between the highest floor and the current floor (23 - 11 = 12) compared to the difference between the lowest floor and the current floor (11 - 2 = 9). Since 9 is lower than 12, you would visit the lower floors first then go up.
I do not understand this. Why would we need to consider the entire height of the building when cycling through a list of stops? The elevator doesn’t have to travel all the way to the top each time, it just moves between floors.
Regardless, it seems completely unnecessary to what we are being asked to calculate. If i’m at floor 11 and my options are to go to down to floor 10 or up to floor 12. Nothing in the problem as written indicates I have to care that the floors go up to 23 in making that decision.
It’s not a “10 or 12” thing. The elevator has to stop at all of the requested floors. The decision is about whether the elevator goes up or down first.