FastPrepLongest Contiguous Houses After Each Build

Longest Contiguous Houses After Each Build

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

Initially, no integer position contains a house. The distinct values in queries give house positions in build order.

After every build, return the length of the longest contiguous run of occupied integer positions.

Function

longestHouseSegments(queries: int[]) → int[]

Examples

Example 1

queries = [2,1,3]return = [1,2,3]

The longest occupied segment grows from {2}, to {1,2}, to {1,2,3}.

Example 2

queries = [1,3,0,4]return = [1,1,2,2]

The final segments are {0,1} and {3,4}, both of length two.

Constraints

  • 1 <= queries.length <= 100000
  • -1000000000 <= queries[i] <= 1000000000
  • All positions are distinct.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] longestHouseSegments(int[] queries) {
    // Write your code here.
}
queries[2,1,3]
expected[1,2,3]
Checking account…