FastPrepLazy Filter over a Generator
Problems/Lazy Filter over a Generator

Lazy Filter over a Generator

Squarepoint Capital logoSquarepoint Capital● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Squarepoint Capital first-round video interview for an experienced data platform role. The round also asked Python questions. In this coding question, the candidate was asked what a generator is, then to write their own filter and run it over a generator or a list.

The report gives no signature, tests, limits or examples, so we chose these rules: the source is a fixed list of integers handed out one at a time; the filter test is one of four rules (greater than k, less than k, a multiple of k, not a multiple of k), where a value equal to k fails the two comparisons and 0 counts as a multiple; the filter reads only until it finds its next kept value; a caller takes at most limit values and then stops; and each answer row pairs a kept value with how many source values had been read when it came out, which shows the filter is lazy. An empty result is an empty array.

Our version is about 50% the same as the reported question.

A generator hands out values one at a time, and only when it is asked for the next one. Here, a source generator hands out the integers in values, in order. Each value it hands out counts as one read.

Write your own lazy filter that takes its values from the source. The filter keeps a value x only if it passes the test named by rule:

  • "GREATER_THAN": keep x when x > k.
  • "LESS_THAN": keep x when x < k.
  • "DIVISIBLE_BY": keep x when x is a multiple of k. This includes 0 and negative multiples.
  • "NOT_DIVISIBLE_BY": keep x when x is not a multiple of k.

Each time the filter is asked for its next value, it reads from the source one value at a time and returns the first value that passes. It never reads further than that. If the source runs out first, the filter has no more values.

A caller asks the filter for values until it has received limit values or the filter runs out. Then it stops, so it never asks for a value it will not use.

Return one row [x, reads] for each value x the caller receives, in the order received. reads is the number of values the source has handed out at the moment the filter returns x. If the caller receives no values, return an empty array.

Function

lazyFilter(values: int[], rule: String, k: int, limit: int) → int[][]

Examples

Example 1

values = [3,8,-4,7,10,6]rule = "DIVISIBLE_BY"k = 2limit = 2return = [[8,2],[-4,3]]
  • The first request reads 3, which is odd, so the filter skips it and reads 8. 8 is kept after 2 reads: [8, 2].
  • The second request reads -4, which is divisible by 2. It is kept after 3 reads: [-4, 3].
  • The caller now has limit = 2 values and stops, so 7, 10 and 6 are never read.

Example 2

values = [5,4,12,0,9]rule = "GREATER_THAN"k = 4limit = 10return = [[5,1],[12,3],[9,5]]

5, 12 and 9 are greater than 4; they are read 1st, 3rd and 5th. 4 is not kept, because it is not greater than itself. The source runs out after three kept values, fewer than limit = 10, so the answer has three rows.

Example 3

values = [-7,6,-2,5]rule = "NOT_DIVISIBLE_BY"k = 2limit = 1return = [[-7,1]]

-7 is not divisible by 2, so it is kept on the very first read. The caller wanted only one value, so nothing else is read.

Constraints

  • 0 <= values.length <= 1000
  • -10^6 <= values[i] <= 10^6
  • rule is one of "GREATER_THAN", "LESS_THAN", "DIVISIBLE_BY" or "NOT_DIVISIBLE_BY".
  • -10^6 <= k <= 10^6
  • If rule is "DIVISIBLE_BY" or "NOT_DIVISIBLE_BY", then 1 <= k.
  • 0 <= limit <= 1000

More Squarepoint Capital Phone Screen questions

  • Moving Average of a Data StreamPHONE SCREEN · Seen Nov 2026
  • Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
  • Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
  • Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
  • Combine Two Index SequencesPHONE SCREEN · Seen Aug 2026
  • Parse, Normalize, and Combine PolynomialsPHONE SCREEN · Seen Aug 2026
  • Sorted Insertion SnapshotsPHONE SCREEN · Seen Aug 2026
  • Strong and Weak Reference LifecyclePHONE SCREEN · Seen Aug 2026
  • Target Sum Across Two Sorted ArraysPHONE SCREEN · Seen Aug 2026
  • Classify Heap Addresses from a Memory SnapshotPHONE SCREEN · Seen Nov 2025

Similar questions at other companies

  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
  • Stepped IteratorBridge · PHONE SCREENBridge interview questions
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Count Events in Rolling Minute WindowsMeta · PHONE SCREENMeta interview questions
  • Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions

Interview reports that mention this question

  • Squarepoint Capital Data Products First Round: 1 Experience

Squarepoint Capital interview experiences

  • Squarepoint Capital C++ and Python SWE Interviews: 7 Experiences
  • Squarepoint Campus SDE Interviews: 7 Experiences (Part 2 of 2)
  • 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 int[][] lazyFilter(int[] values, String rule, int k, int limit) {
        // Write your code here.
    }
}
Checking account…