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
2d
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 JPMorgan Chase & Co. Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in JPMorgan Chase & Co. Software Developer Intern
>
JPMorgan Chase & Co. Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app