FastPrepSet Command Simulation
Problems/Set Command Simulation

Set Command Simulation

Pure Storage logoPure Storage● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pure Storage onsite interview. The report names the five set APIs and the expected cost of each operation. It leaves unclear how iteration behaves and how the code is run. Our version is about 78% the same as the reported question.

Simulate a set of strings over a finite batch of commands in operations.

  • ["PUT", value] inserts value. Inserting an existing value has no effect.
  • ["LOOKUP", value] emits "true" when the value is present and "false" otherwise.
  • ["REMOVE", value] removes the value when present and otherwise has no effect.
  • ["CLEAR"] removes every value.
  • ["ITERATE"] emits all current values in ascending lexicographic order, joined with commas. It emits the empty string when the set is empty.

Only LOOKUP and ITERATE emit outputs. Return those strings in command order.

Function

runSetCommands(operations: String[][]) → String[]

Examples

Example 1

operations = [["PUT","pear"],["PUT","apple"],["LOOKUP","pear"],["ITERATE"],["REMOVE","pear"],["LOOKUP","pear"],["CLEAR"],["ITERATE"]]return = ["true","apple,pear","false",""]

The first lookup succeeds. Iteration sorts apple before pear; after removal and clear, the later outputs show the updated state.

Example 2

operations = [["PUT","b"],["PUT","b"],["PUT","a"],["ITERATE"],["REMOVE","missing"],["LOOKUP","b"]]return = ["a,b","true"]

Duplicate insertion and removal of an absent value do not change the set.

Constraints

  • 1 <= operations.length <= 200000.
  • Every command is one of PUT, LOOKUP, REMOVE, CLEAR, or ITERATE and has the documented arity.
  • Every value has between 1 and 30 ASCII letters, digits, or underscores.
  • The total number of characters across all commands is at most 2000000.

More Pure Storage interview questions

  • One-Shot Callback Event DispatchONSITE INTERVIEW · Seen Sep 2026
  • Rasterize a Circle with Integer PixelsONSITE INTERVIEW · Seen Sep 2026
  • Perfect AND Tree Leaf UpdatesONSITE INTERVIEW · Seen Aug 2024
  • Constant-Time Set OperationsPHONE SCREEN · Seen Sep 2026
  • Racing ResultsOA · Seen Oct 2024
  • Find DoublesOA · Seen Oct 2024
  • Count Different Palindrome SubstringsOA · Seen Jul 2024
  • Count Palindromic SubstringsOA · Seen Jul 2024
  • Find RepetitionsOA · Seen Nov 2023
  • Bakery Quality ControlOA · Seen Nov 2023

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
  • Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
  • CD Rental SystemOkta · ONSITE INTERVIEWOkta interview questions
  • Order Manager with Partial Cancellations and Indexed QueriesStripe · ONSITE INTERVIEWStripe interview questions
  • Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
  • Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
  • Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA
All Pure Storage interview questionsSee Pure Storage hiring insights
Saved
class Solution {
    public String[] runSetCommands(String[][] operations) {
        // Write your code here.
    }
}
Checking account…