← 返回 ibm 的题目列表Minimum Removal Rounds by Smallest Response Time
类型:qbank
Given response times, repeatedly choose the currently smallest remaining request and remove it together with its left and right neighbours. Return the total number of removal operations needed.
Requirements
Input: an array responseTimes.
Repeated operation:
Choose the current request with the smallest response time.
Remove that request and its current left/right neighbours if they still exist.
Continue until no requests remain.
Output: the number of operations needed to delete the entire sequence.
Notes
This is a priority-queue plus linked-neighbour simulation problem.
Store each element as (responseTime, index) in a min-heap.
Maintain prev[], next[], and an alive[] marker so neighbour removal after earlier operations can be handled correctly.
When a heap entry refers to an already removed index, skip it.
One adjacent IBM summary describes the same family as choosing minimum response-time elements and deleting neighbours; another describes a hammer/removal greedy problem with the same current-minimum flavour but less detail.
Preparation
Implement the min-heap plus prev[] / next[] arrays once without a library linked list; stale heap entries are the main hidden-test trap.
Test monotone arrays, duplicate response times, length-one input, and cases where both neighbours have already been removed by earlier rounds.