Reddit logo

Reddit

San Francisco, CASocial Media

Interview Questions

Hit Counter Implementation

Asked at Reddit
technical
data structures
system design

Implement a hit counter for tracking requests in last 5 minutes.

Class Methods:

class HitCounter {
    hit(timestamp: number): void
    getHits(timestamp: number): number
}

Requirements:

  • Track hits within 5-minute window
  • Optimize for efficient retrieval
  • Handle timestamp ordering
  • Thread-safe implementation

Example: hit(10) hit(9) getHits(100) → 2 hit(201) getHits(400) → 2

Word Ladder Implementation

Asked at Reddit
technical
graphs
bfs

Implement word transformation with shortest path finding.

Part 1: Basic Transformation Check if transformation possible from beginWord to endWord.

Part 2: Shortest Path Find length of shortest transformation sequence.

Example: beginWord = "hit" endWord = "cog" wordList = ["hot","dot","dog","lot","log","cog"] Output: 5 (hit→hot→dot→dog→cog)

Part 3: All Shortest Paths Find all possible shortest transformation sequences.

Share Your Experience at Reddit