Walmart Coding Question – Solved

9 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.

Asked in: Walmart

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |