Katkat

Solve four design-leaning coding problems

TwitchSoftware Engineer · Onsite

Last updated

This multi-part question evaluates algorithmic problem-solving, data structure design and manipulation (such as LRU cache semantics), stateful simulation and scoring logic, chronological quota accounting for billing, and set/map operations for detecting overlaps.

You are given four independent interview-style coding tasks. For each task, implement the requested function/class with clear inputs/outputs and reasonable constraints. (You do not need to integrate the tasks together.)

1) Rock–Paper–Scissors scoring with bonuses

Design a small game engine that computes the score for a sequence of Rock–Paper–Scissors rounds.

Rules

  • Each round has two moves: playerMove and opponentMove, each in {R, P, S}.
  • Outcome:
  • Win: player gets +1 point
  • Tie: player gets 0 points
  • Loss: player gets 0 points
  • Bonus A (win streak): if the player wins two or more rounds in a row, then each win after the first consecutive win gets an extra +1.
  • Example: outcomes W, W, W yields base 1+1+1 plus streak bonus 0+1+1.
  • Bonus B (break a tie): if the previous round was a tie and the current round is a win, the current round gets an extra +1.

Requirements

Given a list of rounds in chronological order, return:

  1. The total score for the whole sequence.
  2. The score earned per round (after bonuses).

Input/Output

  • Input: rounds = [(playerMove1, oppMove1), ..., (playerMoveN, oppMoveN)]
  • Output: (totalScore, perRoundScores)

Constraints: 1 <= N <= 2e5.


2) LRU cache API

Implement an in-memory cache with Least Recently Used (LRU) eviction.

Requirements

Implement a class with:

  • LRUCache(capacity)
  • get(key) -> value | -1 (returns -1 if not found)
  • put(key, value)

Rules:

  • When the cache exceeds capacity, evict the least recently used key.
  • Any successful get makes that key the most recently used.
  • put of an existing key updates its value and makes it most recently used.
  • Target complexity: O(1) average time per operation.

Follow-up (thread safety)

Describe how you would make this cache safe under concurrent access from multiple threads (you do not need to implement concurrency primitives unless explicitly asked).


3) 24-hour notification billing with a daily free quota

A notification service charges based on the number of notifications sent each hour of a day (24 hours total).

Inputs

  • counts[24]: integer array where counts[i] is the number of notifications sent during hour i.
  • freeLimit: total number of notifications per day that are free.
  • unitPrice: cost per notification beyond the free limit.

Billing rule

  • The freeLimit is applied chronologically from hour 0 to hour 23 (first-come-first-served).
  • For each hour, some portion of that hour’s notifications may be free until the daily freeLimit is exhausted.

Output

Return:

  1. totalCost for the day.
  2. hourlyCost[24] where hourlyCost[i] is the cost charged for hour i.

Constraints: 0 <= counts[i] <= 1e9, 0 <= freeLimit <= 1e12, 0 <= unitPrice <= 1e6.


4) Find channels with overlapping followers

You are given a mapping from channels to their followers.

Input

  • channelToFollowers: map/dictionary where channelToFollowers[channel] is a list (or set) of follower IDs.
  • targetChannel: a channel name that exists in the map.

Task

Return all other channels that share at least one follower with targetChannel.

Output

Return a list of channels (excluding targetChannel) that overlap.

Follow-up questions

  • How would you optimize if you need to answer many queries for different `targetChannel` values?
  • What is the time/space complexity of your approach?
  • Constraints (suggested): up to `1e5` channels, total follower memberships up to `1e6`.