The Amazing Race
Practice
3.4 (71 votes)
Data structures
Implementation
Medium
Problem
58% Success 19701 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

As the Formula One Grand Prix was approaching, the officials decided to make the races a little more interesting with a new set of rules. According to the new set of rules, each driver will be given a vehicle with different height and the driver with maximum SIGHT would win the race.

Now, SIGHT of a driver is defined by \(( X * P ) % 1000000007\), where

X = number of drivers he can see in front of him + number of drivers he can see behind him
P = position of the driver in a given scenario ( index of the driver array is \(1-N\) indexed )

As all the drivers are moving in a straight line, a driver i cannot see beyond another driver j if height of \(j >= \) height of driver i.

INPUT
First line of the input contains t, the number of test cases. The 1st line of each test case consists of a single integer n, the number of drivers. Second line contains n space separated integers H[1], H[2], H[3]...H[n] denoting the heights of the drivers \(1, 2, 3....n\).

OUTPUT
Output for each test case should be a single line displaying the index of the winning driver. In case of ties, display the driver with minimum index.

CONSTRAINTS
\(0 \le t \le 50\)
\(1 \le n \le 10 ^ 5\)
\( 0 \le H[i] \le 10 ^ 6 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
24 votes
Tags:
Data StructuresImplementationC++ArraysBasics of bit manipulationBit manipulation1-D
Points:30
64 votes
Tags:
ArraysData StructuresMediumOne-dimensionalStacks
Points:30
40 votes
Tags:
1-D ArrayArraysData StructuresEasyOne-dimensionalOpenapproved