Parkour

Company: sprinklr_13july

Difficulty: medium

Problem Statement

Parkour Problem Description Michael Scott has just discovered parkour and wants to cross the office by jumping across the tables. He is not very fit, so he cannot keep climbing to higher and higher tables. He therefore fixes the following strategy. The tables are numbered 0 to n-1 from one end of the office to the other, and arr[i] is the height of table i . Michael always jumps towards the far end of the office, so every jump moves to a strictly larger index. He counts his jumps starting from 1. On an odd-numbered jump (the 1st, 3rd, 5th, ...) he jumps to the lowest table among the later tables whose height is greater than or equal to the height of his current table. On an even-numbered jump (the 2nd, 4th, 6th, ...) he jumps to the highest table among the later tables whose height is less than or equal to the height of his current table. If no later table satisfies the rule for the jump he has to make, he is stuck and stops there. Michael reaches the other end of the office exactly wh