FastPrepObserve a Lazy Generator
Problems/Observe a Lazy Generator

Observe a Lazy Generator

Squarepoint Capital logoSquarepoint Capital● EasyNEW GRADONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports describe coding with Python generators but do not preserve the original snippets. This practice supplies a finite-value fixture, next/close commands, observation strings, and limits. It covers the generator capability; other coded concepts remain unspecified. Approximate source match: 35%.

Model the observable behavior of a lazy value generator. For this exercise, assume it yields the supplied integers in values, in their original order, one at a time. This is a practice fixture, not a request to invent a generated sequence.

Process operations in order and return one observation string per operation:

  • NEXT: yield the next unused value as value:<integer>. If no value remains, or the generator is closed, return done.
  • CLOSE: permanently close the generator and return closed. Repeating this operation is harmless and still returns closed.

A successful NEXT consumes exactly one value. A failed NEXT does not restart the generator. Closing it discards access to all remaining values. With no operations, return an empty array.

Keep iteration lazy: do not make a second full copy of the yielded sequence. You may use a native generator or an equivalent cursor or closure that has the same behavior.

Function

observeGenerator(values: int[], operations: String[]) → String[]

Examples

Example 1

values = [4,9]operations = ["NEXT","NEXT","NEXT"]return = ["value:4","value:9","done"]

The first two pulls consume 4, then 9. A third pull observes exhaustion.

Example 2

values = [7,8]operations = ["NEXT","CLOSE","NEXT","CLOSE"]return = ["value:7","closed","done","closed"]

The first pull yields 7. Closing prevents 8 from being yielded. Later pulls stay done; repeated close remains closed.

Example 3

values = []operations = ["NEXT","CLOSE","NEXT"]return = ["done","closed","done"]

An empty generator is exhausted immediately and stays unavailable after close.

Constraints

  • 0 <= values.length <= 500.
  • -1000000 <= values[i] <= 1000000.
  • 0 <= operations.length <= 500.
  • Each operation is exactly NEXT or CLOSE.

More Squarepoint Capital interview questions

  • Mutable Record Store with Error ResultsONSITE INTERVIEW · Seen Sep 2026
  • Maximum SubarrayONSITE INTERVIEW · Seen Aug 2026
  • Product of Array Except SelfONSITE INTERVIEW · Seen Aug 2026
  • Estimate Pi with a Finite SeriesONSITE INTERVIEW · Seen Oct 2025
  • In-Memory Directory and File OperationsONSITE INTERVIEW · Seen Oct 2025
  • Count C++ Constructor and Assignment CallsONSITE INTERVIEW · Seen Jun 2025
  • Order Matching on ExecuteONSITE INTERVIEW · Seen Dec 2024
  • Accumulate Numeric Value ObjectsONSITE INTERVIEW · Seen Sep 2024
  • Differentiate a PolynomialONSITE INTERVIEW · Seen Aug 2023
  • Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
  • Apply Overridden Integer TransformsOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Copy File Bytes with Partial WritesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Policy Violation Set ChecksPinterest · ONSITE INTERVIEWPinterest interview questions
  • Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
  • Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions

Interview reports that mention this question

  • Squarepoint Capital C++ and Python SWE Interviews: 7 Experiences
  • Squarepoint Campus SDE Interviews: 7 Experiences (Part 2 of 2)

Squarepoint Capital interview experiences

  • Squarepoint Capital New Grad SDE OA: 5 Experiences (Part 1 of 2)
All Squarepoint Capital interview questionsSee Squarepoint Capital hiring insights
Saved
class Solution {
    public String[] observeGenerator(int[] values, String[] operations) {
        // write your code here
    }
}
Checking account…