Laser Propagation

Company: Sprinklr_27july

Difficulty: medium

Problem Statement

A research facility has installed N communication towers in a straight line, numbered 1 to N from left to right. The height of the i -th tower is h[i] , and all heights are distinct. Each tower is equipped with a downward-pointing laser transmitter that can establish a direct optical link with another tower. A tower a can transmit a laser signal directly to a tower b if all of the following hold: The receiving tower is shorter than the transmitting tower, i.e. h[b] < h[a] . The receiving tower may be either to the left or to the right of the transmitting tower. Every tower strictly between a and b is shorter than the transmitting tower a . Otherwise the laser beam is blocked by an intermediate tower. A propagation sequence starts at one tower of your choice, which fires its laser at one tower it can reach. Whenever a tower receives the signal it immediately retransmits it, under the same rules, to one further tower. The sequence ends when the current tower chooses to stop or can no