4 kyu

Elevator Action!

6 of 66ITSOES
Description
Loading description...
Algorithms
Performance
  • Please sign in or sign up to leave a comment.
  • K01egA Avatar

    Binary search was overkill here. Perfomance tag means not to check every floor one by one.

  • Kees de Vreugd Avatar
  • dfhwze Avatar

    suggested tags: algorithms, performance

  • Ciprian Amza Avatar

    I am passing all the sample tests and failing most of the random tests, which makes me feel that the random tests cover some extra cases that I am missing from the description and the sample tests. Maybe you could check my current solution and add a few extra sample tests (one or two), which would help to debug the kata?

  • dfhwze Avatar

    This comment has been hidden.

  • dfhwze Avatar

    Day 8 shows that once you reach the current target floor, you won't pick up any additional people going in the same direction anymore, instead you'll prioritise the next person in queue. I'm not sure this situation is explained in the rules.

  • dfhwze Avatar

    I suggest you add a second batch of random tests with small queues (max 15 people) and low amount of floors (max 10 floors buildings). This would help users focus on their algorithm for edge cases they may encounter. I would add up to 500 of such random tests. The current random tests are a good way to address the performance constraints.

  • HerrWert Avatar

    This kata looks amazing, especially because the description seems very realistic. Once a week, I go to a place where I ride the elevators a lot. As I ride, I often begin thinking about how an elevator control algorithm would look. But soon I get to my destination, get off the elevator, and forget about it until the next time. So I never finish my solution. Maybe this kata will help me concentrate long enough to solve it.

    UPDATE: Passing 443 tests so far, then timing out. Pretty happy with that, but I might need to take an entirely more efficient approach to pass 'em all.

  • Ciprian Amza Avatar

    What happens if, for example, the first in the queue is something like (85, 3) and the elevator starts from level 1, and during the road 1-85, more than 5 people will get in and they will continue going to a higher floor than 85. Would the first person from the queue have to wait until the elevator comes back empty? Will the elevator stop?

  • dfhwze Avatar

    You don't explain whether the elevator gives priority to its own direction or to the next person in queue.

    For instance, in the example below, elevator moves UP to 4. Then what happens,

    • keep moving up, as there is another person in queue higher and from spec: "You can't switch directions while holding passengers."
    • OR, move down, as we give priority to the direction of this first person in queue
    start: 1
    queue: [ { from: 4, to: 2}, { from 5, to: 4 } ]
    

    Or, the following:

    • we want to go to 4, pick up 2 first, 4 does not get in since they want other direction, drop at 5, pick up at 4 on way down and drop at 2
    • OR we go to 4, ignore 2 on the way up since 2 wants other direction as 4, drop at 2 on way down, pick up other person at 2 and drop at 5 on way up again
    start: 1
    queue: [ { from: 4, to: 2}, { from 2, to: 5 } ]
    
  • mortonfox Avatar

    What happens if the elevator is full but there is a floor along the way where someone wants to go in that direction? Does it still stop at that floor without picking up anyone?

    Or is it one of those "smart" elevators that I saw in a city center hotel once that knows to keep moving in that scenario?

  • Blind4Basics Avatar

    isn't that too close to this ?

  • Voile Avatar

    Random tests generate negative from/to, which is unphysical, and certainly unexpected.

  • dfhwze Avatar

    JS is full of issues:

    • Empty solution times out
    • method "cmp" does not exist