FastPrepSparse Set with Constant-Time Updates
Problems/Sparse Set with Constant-Time Updates

Sparse Set with Constant-Time Updates

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes using two arrays to act like low-level memory, so that adding and deleting at any position takes O(1), like a hash set. Here we use the usual dense and sparse set operations, and repeating an operation has no extra effect. Our version is about 83% the same as the reported question.

Maintain a set of integers in [0,maxValue] using a dense array and a sparse position array.

  • [0,value] adds value; adding an existing value changes nothing.
  • [1,value] removes value; removing a missing value changes nothing.
  • [2,value] queries membership and produces one Boolean output.

Every operation must run in worst-case O(1) time. Return query results in operation order.

Function

processSparseSet(maxValue: int, operations: int[][]) → boolean[]

Examples

Example 1

maxValue = 10operations = [[0,3],[0,7],[2,3],[1,3],[2,3],[2,7]]return = [true,false,true]

Three and seven are added; removing three does not affect seven.

Example 2

maxValue = 2operations = [[0,1],[0,1],[2,1],[1,1],[1,1],[2,1]]return = [true,false]

Duplicate add and remove operations are idempotent.

Example 3

maxValue = 0operations = []return = []

No operations produce no query results.

Constraints

  • 0 <= maxValue <= 1000000.
  • 0 <= operations.length <= 200000.
  • Every operation has exactly two integers and a value in [0,maxValue].
  • Operation type is 0, 1, or 2.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Asteroid CollisionSiemens · PHONE SCREEN
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions

Interview reports that mention this question

  • Google PhD Early Career ML Interviews: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean[] processSparseSet(int maxValue, int[][] operations) {
        // Write your code here.
    }
}
Checking account…