Longest Run of Houses
MetaMedium
Houses are built one at a time along a street. Two houses are contiguous when their positions are consecutive integers, and a run is a maximal group of contiguous houses.
Part 1: Longest run after each build
You are given an integer array queries, where queries[i] is the position where the i-th house is built.
Return a list whose i-th value is the length of the longest run after the first i + 1 builds.
Building at a position that already has a house changes nothing.
- Example 1
- queries
[2,10,3,4]- Output
[1,1,2,3]
Why: After house 2 the longest run is 1, and house 10 does not touch it. House 3 joins 2 into a run of 2, and house 4 extends it to 3.
Constraints
1 <= len(queries) <= 10^51 <= queries[i] <= 10^9
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.