This question evaluates algorithmic problem-solving for interval manipulation and stateful data-structure design for maintaining and ordering agent averages, probing skills in sorting/merging, incremental updates, complexity analysis, and deterministic tie-breaking within the Coding & Algorithms domain.
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:
Follow-up:
newInterval
into the existing set and return the merged result efficiently.
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:
getTopAgents()
may be called many times; aim for an efficient approach across many operations.
Constraints (assume typical interview scale):
10^5
total API calls.
getTopAgents()
calls should not require excessive recomputation each time.