FunctionRacerProblemsRace

Next Taller Around the Table

EasyStacks and queuesPython, JavaScript, TypeScript, Java, C++

People sit around a round table, and heights[i] is the height of the person in seat i. Going clockwise means going from seat i to seat i + 1, and from the last seat back to seat 0.

Return a list where item i is the seat of the first person clockwise from seat i who is strictly taller than person i, or -1 if nobody at the table is taller. Return an empty list for an empty table.

Example 1

heights [160,150,170,150]
returns [2,2,-1,0]

Seat 3 wraps around to seat 0, whose 160 beats 150. Nobody is taller than the 170 in seat 2.

Example 2

heights [175,175]
returns [-1,-1]

An equal height does not count as taller.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems