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.)
Design a small game engine that computes the score for a sequence of Rock–Paper–Scissors rounds.
playerMove
and
opponentMove
, each in
{R, P, S}
.
+1
point
0
points
0
points
W, W, W
yields base
1+1+1
plus streak bonus
0+1+1
.
Given a list of rounds in chronological order, return:
rounds = [(playerMove1, oppMove1), ..., (playerMoveN, oppMoveN)]
(totalScore, perRoundScores)
Constraints: 1 <= N <= 2e5.
Implement an in-memory cache with Least Recently Used (LRU) eviction.
Implement a class with:
LRUCache(capacity)
get(key) -> value | -1
(returns
-1
if not found)
put(key, value)
Rules:
capacity
, evict the
least recently used
key.
get
makes that key the most recently used.
put
of an existing key updates its value and makes it most recently used.
O(1)
average time per operation.
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).
A notification service charges based on the number of notifications sent each hour of a day (24 hours total).
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.
freeLimit
is applied
chronologically
from hour
0
to hour
23
(first-come-first-served).
freeLimit
is exhausted.
Return:
totalCost
for the day.
hourlyCost[24]
where
hourlyCost[i]
is the cost charged for hour
i
.
Constraints: 0 <= counts[i] <= 1e9, 0 <= freeLimit <= 1e12, 0 <= unitPrice <= 1e6.
You are given a mapping from channels to their followers.
channelToFollowers
: map/dictionary where
channelToFollowers[channel]
is a list (or set) of follower IDs.
targetChannel
: a channel name that exists in the map.
Return all other channels that share at least one follower with targetChannel.
Return a list of channels (excluding targetChannel) that overlap.
targetChannel
values?
Constraints (suggested): up to 1e5 channels, total follower memberships up to 1e6.