Tide Leaders

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Tide Leaders

A coastal research team records tide levels throughout the day in an array tides. A tide level is called a leader if it is greater than or equal to every tide level recorded after it. The final tide reading is always a leader because there are no readings after it. Given the array tides, return all leader tide levels in the same order in which they appear.

Examples

Example 1
Input:
tides = [16, 17, 4, 3, 5, 2]
Output:
[17, 5, 2]

Explanation: 17 is greater than all tide levels after it. 5 is greater than 2. The last reading 2 is always a leader.

Approach hint

Think about scanning from the right side of the array.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp