House Segments After Removals
Problem statement
houses lists distinct occupied integer positions. Every value in queries names a currently existing house to remove.
After each removal, return the number of maximal contiguous runs of remaining house positions.
Function
houseSegmentsAfterRemovals(houses: int[], queries: int[]) → int[]Examples
Example 1
houses = [1,2,4,5]queries = [2,4,1,5]return = [2,2,1,0]Removing 2 and then 4 leaves two separated singleton segments; only one segment remains after removing 1.
Example 2
houses = [3]queries = [3]return = [0]Removing the only house leaves no segments.
Constraints
1 <= houses.length == queries.length <= 100000- Each house is removed exactly once.