There are N Buildings in a row which have heights from (A1 to AN)
Robot P & Q wants to land on top of a maximum number of buildings starting from building K.
But there are two conditions for moving from one building to another.
Robot P can only move to the right side from position K and it can never land on a lower-height building.
Robot Q can only move to the left side from position K and it can never land on a higher-height building.
By following the above rules, you need to determine the steps for Robot P & Q and print the building heights on which they will land sequentially.
Firstly we need to take the input N, K - the number of the buildings and the starting position.
Then we take input of the heights for all N buildings.
Now according to the rules, Robot P will first land on the Kth building, then it will go to the (K+1)th to Nth building one by one and check if it can land on that building or not.
In the same way, Robot Q will first land on the Kth building, then it will go to the (K-1)th to 1st building one by one and check if it can land on that building or not.
While checking, if the ith building height follows the rules for the specific robots, then print the building height sequentially for Robot P and Q respectively.