[QABANK] Calendar Busy View
Problem Description:
Summary: Given list of events of a given day in a calendar, write an algorithm to return a list
of busy view time slots. Busy view is created by consolidating adjacent and overlapping event
time slots without showing details of individual events.
Details: Each event in calendar has a start time, end time & some title. Events can start at
any minute (granularity at the minute only, no seconds).
Sample inputs - Expected outputs
Input: list of following events
(100,300,"Some Event") // 1:00 am to 3:00 am
(115,145,"Some Event")
(145,215,"Some Event")
(200,400,"Some Event")
(215,230,"Some Event")
(215,415,"Some Event")
(600,700,"Some Event")
(500,600,"Some Event")
Output: Based on above events, my busy view should show like this:
(100,415) // Busy from 1am to 4:15am
(500,700) // Busy from 5am to 7am
这题要求把当天的所有日程事件按照时间合并成 Busy View,即把所有重叠或相邻的时间段合并成连续区间。典型解法是先按开始时间排序,再遍历并逐段合并。最终输出就是若干个不重叠的忙碌时间块。
彭博面试题:识别最先崩溃的进程(树结构中的根故障)
An operating system has the following rules:
1. Each process is spawned from a parent process except the first process.
2. The parent process is aware of its children.
3. If a parent process is aborted, all the child processes get aborted.
One of the processes crashed and brought down a lot of other processes along with it.
A log parser found the set of all the processes which have crashed. This set of processes,
along with sub-process child relationships for each process, is then passed to your function.
Identify the id of the process which crashed first.
Example tree:
15
/ \
7 5
/ \ \
9 4 1
/ \
2 11
Input:
[
Process(9, [2,11]),
Process(11, []),
Process(4, []),
Process(7, [9,4]),
Process(2, []),
]
Output: 7
题目给出所有已崩溃的进程及其子进程关系。由于父进程崩溃会导致所有后代都崩溃,所以最先崩溃的一定是这些崩溃节点中的“最高祖先”,也就是那个没有崩溃父节点的进程。解法是把所有 crashed pid 存入集合,再查每个节点是否有 crashed 父节点,找出那个没有父节点的即可。
正文完