Fastest Horse Problem Statement
Given ‘N’ horses running in separate lanes, each horse's finish time is provided in an array. You are tasked to process 'Q' queries. For each query, determine the time taken by the fastest horse in a specified lane range.
Input:
The first line contains an integer ‘T’ representing the number of test cases.
Each test case starts with two space-separated integers ‘N’ and ‘Q’, representing the number of horses and the number of queries.
The second line of each test case contains an array of ‘N’ integers, where each element denotes the finish time of a horse.
The next ‘Q’ lines contain two integers ‘L’ and ‘R’ indicating the range of horses to be considered for the query.
Output:
For each query, output the time taken by the fastest horse within the specified range.
Each test case result should be output on a new line.
Example:
Input:
T = 1
N = 5, Q = 2
FINISHTIME = [3, 1, 4, 1, 5]
Queries: (L, R) = (0, 2) and (2, 4)
Output:
1 1
Explanation:
For the first query, the fastest horse within the range {3, 1, 4} has the time 1, and for the second query, the fastest within {4, 1, 5} is again 1.
Constraints:
- 1 <= T <= 50
- 1 <= N <= 10000
- 1 <= Q <= 10000
- 1 <= FINISHTIME[i] < 10^9
- 0 <= L <= R < N
Note:
The fastest horse is the one taking the minimum time to finish.
You are not required to print, only implement the function.

AnswerBot
4mo
Given finish times of horses, determine fastest horse in specified lane ranges for multiple queries.
Iterate through each query and find the minimum finish time within the specified range of horses.
Use...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at JPMorgan Chase & Co.
Q. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
Q. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
Q. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for JPMorgan Chase & Co. Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

