You have an array of integers audiobooks where audiobooks[i] is the amount of time in minutes needed to listen to the i-th audiobook fully. You are listening to the audiobooks in a cyclic order:
- For the first time, you pick the audiobook at index
0on your list. - The next time, you pick the audiobook at index
1on your list. - The next time, you pick the audiobook at index
2on your list. - After picking the last audiobook on your list, you return to index
0again.
Also, you have a list of event logs. An event can be:
"LISTEN <minutes>"— pick the next audiobook following the cyclic order described above and listen to it for<minutes>time if you have not finished that audiobook yet. If you complete the book, it should stay on the list, so audiobook indices stay the same."DROP <i>"— you lose interest in the audiobook at indexiand decide not to listen to it in the future. The audiobook is not removed from the list, so all indices stay the same.
Dropping an audiobook does not affect the listening order. For the next LISTEN operation, continue after the audiobook you listened to last.
Return the index of the audiobook with the greatest total listening time after processing all events. If there is a tie, return the largest index.
这道 Uber OA 题的核心是模拟“循环收听 + 删除屏蔽”过程,并维护每本有声书的累计收听时长。对于 LISTEN 事件,需要按环形顺序找到下一本未被 DROP 且尚未完成的位置,把给定分钟数累加到该书上;对于 DROP 事件,只需把对应下标标记为不可再选,但不要真的删除元素,因为题目要求索引保持不变。最后在所有有声书里找累计时长最大的下标,若有并列取更大的下标。实现上通常用一个当前指针 + visited/removed 标记 + 累积数组即可,时间复杂度可以做到接近事件总数线性。