Problem · Array
Neighboring House Groups
Learn this problemProblem statement
Houses occupy distinct integer coordinates on a straight line. Two remaining houses are neighbors when their coordinates differ by exactly 1. A neighboring group is a maximal set of remaining houses connected by this relation.
For each value in instructions, delete that house and append the current number of neighboring groups to the answer. Every instruction names a house that is still present.
Return the group counts in instruction order.
Function
neighboringHouseGroups(houses: int[], instructions: int[]) → int[]Examples
Example 1
houses = [2,1,3,4,6,7,9]instructions = [6,3,9]return = [3,4,3]After deleting 6, the groups are [1,2,3,4], [7], and [9]. Deleting 3 splits the first group, and deleting 9 removes one singleton group.
Constraints
1 <= houses.length <= 2000001 <= instructions.length <= houses.length-10^9 <= houses[i] <= 10^9- House coordinates are distinct.
- Every instruction names a currently present house.
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024