Count House Segments After Sequential Destruction
Updated
Problem statement
Given an array houses of distinct integer house locations and an array queries of distinct locations that all appear in houses, destroy the queried houses in order.
A house segment is a maximal group of remaining houses at consecutive integer locations. After each destruction, record the number of remaining segments.
Return one segment count for every query, in query order.
Function
countHouseSegmentsAfterDestruction(houses: int[], queries: int[]) → int[]Examples
Example 1
houses = [1, 2, 3, 6, 7, 9]queries = [6, 3, 7, 2, 9, 1]return = [3, 3, 2, 2, 1, 0]Initially the segments are [1, 2, 3], [6, 7], and [9]. Removing the houses in query order leaves 3, 3, 2, 2, 1, and finally 0 segments.
Example 2
houses = [2, 4, 5, 6, 7]queries = [5, 6, 2]return = [3, 3, 2]Removing 5 splits [4, 5, 6, 7] into two segments. Removing 6 preserves the segment count, and removing 2 leaves two segments.
Constraints
1 <= houses.length <= 1000001 <= queries.length <= houses.length-10^9 <= houses[i] <= 10^9- All values in
housesare distinct. - Every value in
queriesappears inhouses. - All values in
queriesare distinct.
More ByteDance interview questions
- Sorted Absolute-Difference Sums Across Cyclic ShiftsOA · Seen Aug 2026
- Count Numbers with an Even Digit CountOA · Seen Aug 2026
- Sort Concentric Matrix Borders ClockwiseOA · Seen Aug 2026
- Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
- Matrix EscapePHONE SCREEN · Seen Nov 2026
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Search a Row- and Column-Sorted MatrixONSITE INTERVIEW · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Payment Partner RoutingStripe · OAStripe interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Process Banking OperationsVercel · OA
- First Completed Mingo LineEpic · OAEpic interview questions
- HTTP Request RedirectionAmazon · OA
- Hungarian Lottery Winner CountsAlpaca · OA
- Cheating CodemakerJane Street · OAJane Street interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Maximum Satisfied CustomersAtlassian · OAAtlassian interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience