Neighboring House Groups
Updated
Problem 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 Online Assessment questions
- 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
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- Minimum Contiguous ReplacementsAmazon · OA
- Longest Contiguous Houses After Each BuildZipRecruiter · OAZipRecruiter interview questions
- Group Linked Merchant RecordsStripe · PHONE SCREENStripe interview questions
- Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions
- Count Overlapping Square PairsRamp · OARamp interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions