Problem Analysis:

Observation:
  • 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.

Solution Idea:
  • 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.

Statistics

84% Solution Ratio
Anamul1210Earliest, 5M ago
Modhusudon1687Fastest, 0.0s
emon192002Lightest, 5.2 MB
rudro25Shortest, 550B
Toph uses cookies. By continuing you agree to our Cookie Policy.