Problem 1: Merge overlapping intervals
You are given a list of closed intervals intervals, where intervals[i] = [start_i, end_i] and start_i <= end_i.
Task: Merge all overlapping intervals and return a new list of non-overlapping intervals that cover the same ranges.
Input:
-
intervals
: an array/list of
[start, end]
pairs (not necessarily sorted)
Output:
-
A list of merged, non-overlapping intervals (order can be by increasing start)
Follow-up:
-
Support inserting one additional interval
newInterval
into the existing set and return the merged result efficiently.
Problem 2: Implement agent-rating APIs with ordering by average
Design and implement a data structure that supports the following APIs for rating “agents” by name.
-
rateAgent(name, score)
: record a new rating for the agent
name
.
-
name
is a string identifier.
-
score
is an integer in
[1, 5]
.
-
getTopAgents()
: return a list of agent names sorted by their
current average score
in
descending
order.
Details / requirements:
-
Each agent can receive many ratings over time.
-
The average for an agent is computed over all ratings recorded so far for that agent.
-
getTopAgents()
may be called many times; aim for an efficient approach across many operations.
-
Define a deterministic tie-breaker for equal averages (e.g., by name ascending).
Constraints (assume typical interview scale):
-
Up to ~
10^5
total API calls.
-
Many repeated
getTopAgents()
calls should not require excessive recomputation each time.