FastPrepCount Recorded Events in Time Intervals
Problems/Count Recorded Events in Time Intervals

Count Recorded Events in Time Intervals

Snowflake logoSnowflake● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Counting events by timestamp is about 75% the same as the reported question. This exercise comes from a collection of interview-prep questions, not from one dated interview. We chose these. There are record and query operations. Time intervals include both ends. An operation sees only what came before it. We also set how duplicate events count, the input form, finite limits and the examples.

You are given an array called operations. Start with no recorded events and process the rows from first to last. Each row contains three integers:

  • [0, time, 0]: Record one event at timestamp time, a nonnegative integer. The last 0 is a required placeholder.
  • [1, low, high]: Count the events recorded so far whose timestamps are between low and high, including both ends.

Follow these rules:

  • Each record operation adds a separate event. If two events have the same timestamp, count both.
  • Timestamps and query ranges do not have to be in time order.
  • A query only counts events recorded by earlier rows. Events recorded by later rows do not count toward that query.
  • A query does not add or remove events.

Return the query counts in the order the queries appear. Do not add an output entry for a record operation. If there are no queries, return an empty array. Do not change operations.

Function

countEvents(operations: int[][]) → int[]

Examples

Example 1

operations = [[0,5,0],[0,5,0],[0,9,0],[1,5,5],[1,5,9]]return = [2,3]

Two separate records at time 5 both count. The inclusive intervals contain 2 and 3 recorded events.

Example 2

operations = [[1,0,100],[0,10,0],[1,0,9],[0,3,0],[1,0,10]]return = [0,0,2]

Queries use only earlier record operations. A later operation may record an earlier timestamp; it contributes to later queries.

Example 3

operations = []return = []

No operations produce no query results.

Constraints

  • 0 <= operations.length <= 2000; every row has exactly three integers.
  • Each row is either [0, time, 0] with 0 <= time <= 10^9, or [1, low, high] with 0 <= low <= high <= 10^9.
  • Counts fit in a signed 32-bit integer. A batch with no queries returns an empty array.

More Snowflake Phone Screen questions

  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
  • Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
  • Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
  • Greedy Person-Cake Matching DistancePHONE SCREEN · Seen Nov 2026
  • Tree Height After Child PromotionPHONE SCREEN · Seen Oct 2026
  • Minimum StackPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Good Ways to Split an ArraySalesforce · PHONE SCREENSalesforce interview questions
  • Two Non-Overlapping Increasing BlocksAdobe · PHONE SCREENAdobe interview questions
  • Random Pick with Weight Using Recorded DrawsMeta · PHONE SCREENMeta interview questions
  • Longest Run of Ones After Flipping k ZerosC3.ai · PHONE SCREENC3.ai interview questions
  • Totals from a Tiered Rate TableMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Choose ContainersIMC Trading · OAIMC Trading interview questions
  • Random Pick with Weight Using Recorded DrawsAmazon · ONSITE INTERVIEW
  • TikTok Metrics AnalysisTikTok · OATikTok interview questions
  • Multinomial Sampling with Distribution ChecksNVIDIA · ONSITE INTERVIEWNVIDIA interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public int[] countEvents(int[][] operations) {
        // Write your solution here.
    }

}
Checking account…