Trains the technique from
LeetCode 1762Buildings With an Ocean ViewThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Grain silos stand in one straight line along a rail spur. heights[i] is the height of the silo at index i, and the indices run from the far end of the spur towards the river, so the river lies just past the last silo in the list.
A silo has a clear line to the river when every silo standing between it and the river is strictly shorter than it is. A silo of exactly the same height blocks the line, and the silo closest to the river has nothing in front of it at all.
Return the indices of all silos with a clear line to the river, in increasing order.
Example 1
Indices 2, 5 and 6 each stand taller than everything left between them and the river. Index 4 is beaten by the equally tall silo at index 5, so it is left out.
Example 2
All three silos match in height, so only the one nearest the river keeps its line.
Example 3
Index 0 towers over the rest of the row, index 3 only has the short silo at index 4 in front of it, and index 4 is nearest the river.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def silos_with_river_view(heights: list[int]) -> list[int]:public int[] silosWithRiverView(int[] heights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.