There is a building with an infinite number of floors and you are the only passenger in an elevator which can lift an infinite number of people. You are going home, but before the elevator gets to your floor, the elevator stops at another floor to allow people to enter the elevator and input their destination floors. Your program should handle the floor order correctly
You will be given 3 inputs (the order of input doesn't matter but you need to specify the expected order of inputs):
- Integer - The number of the floor where the people entered the elevator
- Integer - Your destination floor
- Array of integers - The destination floors of entered people
You must output an array of integers with the numbers of floors (including yours) ordered correctly
The correct order is this order, where first the floors that are in the direction of your movement go in an ordered order, and then the floors that are in the direction opposite to yours go in reverse order
- The floor where the people entered is the floor where elevator already stopped so this floor should not be in the order of future destinations (output array)
- There will not be any duplicates in the input array
- Your destination floor will not be in the input array
For example let's say that elevator stopped at the ground floor, your destination is 3rd floor and people entered [4,-2,-5,2,-4,1,5]
So the output of must be [1,3,4,5,-2,-4,-5]
Test cases: (feel free to add more test cases)
0, 3, [4,-2,-5,2,-4,1,5] --> [1,2,3,4,5,-2,-4,-5]
0, -3, [4,-2,-5,2,-4,1,5] --> [-2,-3,-4,-5,1,2,4,5]
5, 10 [1,3,7,9,11,-3,-10] --> [7,9,10,11,3,1,-3,-10]
The shortest code in each programming language wins!