🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 23 - 100% Working Solution | Buy Now
Description
11 Live
Will We Meet
In the bustling town of Skyline Street, Jatin and Mano, two childhood friends, often challenge each other to exciting games. One day, they came up with a unique adventure-"The Climb of Heights."
Skyline Street consists of N buildings, each with a unique height, forming a magnificent skyline. The friends decide to start from their respective buildings and see if they can meet on a taller building by following a simple rule:
They can only move to the right (towards buildings with greater heights than their current one).
Once they reach a taller building, they continue the journey until no taller building exists in front of them.
Excited by the challenge, they come to you, the town's wise strategist, to predict their meeting point. Given a list H representing the heights of the buildings and multiple queries where Jatin and Mano start from different buildings, your task is to determine the leftmost building where they can meet. If no such meeting point exists, return -1.
Can you help Jatin and Mano navigate their way through Skyline Street and find out if they can meet atop a grand building?
|Input Format
The first line of input contains two integers N and 'O' representing the number of buildings in the city and 'O' the number of queries.
The second line of input contains N space-separated integers representing the heights of the buildings.
The next Q lines of input contain 2 space-separated integers J and M representing the starting positions of Jatin and Mano.