AI Role: Collection with Add and Remove Operations
Updated
Problem statement
Maintain an initially empty collection through an ordered sequence of add and remove operations. The collection can hold several copies of the same integer.
[1, value]adds one copy ofvalue.[2, value]removes one copy ofvalueif one is present. Otherwise it does nothing.
After all operations, return every remaining element in ascending numeric order, including duplicates. Sorting is only the output convention; the collection does not need to remain sorted during updates.
Function
applyCollectionOperations(operations: int[][]) → int[]Examples
Example 1
operations = [[1,4],[1,2],[1,4],[2,4],[2,9]]return = [2,4]The three additions create two copies of 4 and one copy of 2. Removing 4 deletes one copy. Removing absent 9 changes nothing. The sorted final collection is [2,4].
Example 2
operations = [[2,1],[1,-3],[2,-3]]return = []The initial removal does nothing. The addition and removal of -3 cancel, leaving an empty collection.
Constraints
0 <= operations.length <= 2000.- Every operation row contains exactly
2integers. - Every integer in an operation row is from
-10^9through10^9. - The first integer of each operation is either
1or2.
More Apple Phone Screen questions
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
- Maintain a Consistent-Hashing RingPHONE SCREEN · Seen Oct 2026
- Count Nodes in a ChainPHONE SCREEN · Seen Oct 2026
- Run-Length DecodingPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Popular and Instant-Runoff Election WinnersCoursera · PHONE SCREEN
- Resolve Visible User FeaturesStripe · PHONE SCREENStripe interview questions
- Credit Card Command ProcessorChime · PHONE SCREEN
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
- HTTP Request RedirectionAmazon · OA
- P&L Leaderboard OperationsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)