PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Snapchat

Implement a Timestamped Counter

Last updated: Apr 16, 2026

Quick Overview

This question evaluates the ability to design and implement time-indexed counting data structures, reason about strictly increasing timestamps and query semantics, and consider performance and scalability trade-offs.

  • medium
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Implement a Timestamped Counter

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a data structure that records calls to an `increment` method. Requirements: - Each call to `increment(timestamp)` receives an integer `timestamp`. - Timestamps are strictly increasing across calls. - Implement `query(t)` to return how many times `increment` was called with a timestamp greater than `t`. Example: - Calls: `increment(1)`, `increment(3)`, `increment(3)`, `increment(10)` - `query(3)` should return `1` if `query` means strictly after `3`, or `1` plus any later duplicates depending on the exact interpretation. Make your API behavior explicit. Follow-up discussion: 1. How would you support a very high call rate, where `increment` may be invoked many times per second? 2. How would you optimize query performance further? 3. If the requirements were extended to support counting calls in any time interval `[start, end]`, what data structures would you consider?

Quick Answer: This question evaluates the ability to design and implement time-indexed counting data structures, reason about strictly increasing timestamps and query semantics, and consider performance and scalability trade-offs.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a custom list with iterator and map - Snapchat (medium)
Snapchat logo
Snapchat
Mar 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Implement a data structure that records calls to an increment method.

Requirements:

  • Each call to increment(timestamp) receives an integer timestamp .
  • Timestamps are strictly increasing across calls.
  • Implement query(t) to return how many times increment was called with a timestamp greater than t .

Example:

  • Calls: increment(1) , increment(3) , increment(3) , increment(10)
  • query(3) should return 1 if query means strictly after 3 , or 1 plus any later duplicates depending on the exact interpretation. Make your API behavior explicit.

Follow-up discussion:

  1. How would you support a very high call rate, where increment may be invoked many times per second?
  2. How would you optimize query performance further?
  3. If the requirements were extended to support counting calls in any time interval [start, end] , what data structures would you consider?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.