在CMU Solo OS是一种怎样的体验?
我想很多CMU的同学在选课的时候都搜到过关于15410/15605 Operating System Design and Implementation这门课的传说,比如这篇,比如这篇。BTW,我是从前面那篇介绍知道的这门课。以前学长们的介绍都挺详细了,我在这里就是记录一下我这个学期上这门课的体会吧,有很多地方与前人的介绍会有重复,毕竟这门课应该好久没有改过了😑。
我想很多CMU的同学在选课的时候都搜到过关于15410/15605 Operating System Design and Implementation这门课的传说,比如这篇,比如这篇。BTW,我是从前面那篇介绍知道的这门课。以前学长们的介绍都挺详细了,我在这里就是记录一下我这个学期上这门课的体会吧,有很多地方与前人的介绍会有重复,毕竟这门课应该好久没有改过了😑。
We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly connected to the top of the grid, or at least one of its (4-way) adjacent bricks will not drop.
We will do some erasures sequentially. Each time we want to do the erasure at the location (i, j), the brick (if it exists) on that location will disappear, and then some other bricks may drop because of that erasure.
Return an array representing the number of bricks that will drop after each erasure in sequence.
1 | Example 1: |
1 | Example 2: |
Note:
In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. If we reach a node that is terminal (that is, it has no outgoing directed edges), we stop.
Now, say our starting node is *eventually safe *if and only if we must eventually walk to a terminal node. More specifically, there exists a natural number K
so that for any choice of where to walk, we must have stopped at a terminal node in less than K
steps.
Which nodes are eventually safe? Return them as an array in sorted order.
The directed graph has N
nodes with labels 0, 1, ..., N-1
, where N
is the length of graph
. The graph is given in the following form: graph[i]
is a list of labels j
such that (i, j)
is a directed edge of the graph.
1 | Example: |
Note:
graph
will have length at most 10000
.32000
.graph[i]
will be a sorted list of different integers, chosen within the range [0, graph.length - 1]
.We have two integer sequences A
and B
of the same non-zero length.
We are allowed to swap elements A[i]
and B[i]
. Note that both elements are in the same index position in their respective sequences.
At the end of some number of swaps, A
and B
are both strictly increasing. (A sequence is strictly increasing if and only if A[0] < A[1] < A[2] < ... < A[A.length - 1]
.)
Given A and B, return the minimum number of swaps to make both sequences strictly increasing. It is guaranteed that the given input always makes it possible.
1 | Example: |
Note:
A, B
are arrays with the same length, and that length will be in the range [1, 1000]
.A[i], B[i]
are integer values in the range [0, 2000]
.In the following, every capital letter represents some hexadecimal digit from 0
to f
.
The red-green-blue color "#AABBCC"
can be written as "#ABC"
in shorthand. For example, "#15c"
is shorthand for the color "#1155cc"
.
Now, say the similarity between two colors "#ABCDEF"
and "#UVWXYZ"
is -(AB - UV)^2 - (CD - WX)^2 - (EF - YZ)^2
.
Given the color "#ABCDEF"
, return a 7 character color that is most similar to #ABCDEF
, and has a shorthand (that is, it can be represented as some "#XYZ"
1 | Example 1: |
Note:
color
is a string of length 7
.color
is a valid RGB color: for i > 0
, color[i]
is a hexadecimal digit from 0
to f
N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats.
The people and seats are represented by an integer from 0
to 2N-1
, the couples are numbered in order, the first couple being (0, 1)
, the second couple being (2, 3)
, and so on with the last couple being (2N-2, 2N-1)
.
The couples’ initial seating is given by row[i]
being the value of the person who is initially sitting in the i-th seat.
Example 1:
1 | Input: row = [0, 2, 1, 3] |
Example 2:
1 | Input: row = [3, 2, 0, 1] |
Note:
len(row)
is even and in the range of [4, 60]
.row
is guaranteed to be a permutation of 0...len(row)-1
.In a 2D grid
from (0, 0) to (N-1, N-1), every cell contains a 1
, except those cells in the given list mines
which are 0
. What is the largest axis-aligned plus sign of 1
s contained in the grid? Return the order of the plus sign. If there is none, return 0.
An “axis-aligned plus sign of 1s of order k” has some center grid[x][y] = 1
along with 4 arms of length k-1
going up, down, left, and right, and made of 1
s. This is demonstrated in the diagrams below. Note that there could be 0
s or 1
s beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1s.
Examples of Axis-Aligned Plus Signs of Order k:
1 | Order 1: |
Example 1:
1 | Input: N = 5, mines = [[4, 2]] |
Example 2:
1 | Input: N = 2, mines = [] |
Example 3:
1 | Input: N = 1, mines = [[0, 0]] |
Note:
N
will be an integer in the range [1, 500]
.mines
will have length at most 5000
.mines[i]
will be length 2 and consist of integers in the range [0, N-1]
.A string S
of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
Example 1:
1 | Input: S = "ababcbacadefegdehijhklij" |
Note:
S
will have length in range [1, 500]
.S
will consist of lowercase letters ('a'
to 'z'
) only.Given two integers L
and R
, find the count of numbers in the range [L, R]
(inclusive) having a prime number of set bits in their binary representation.
(Recall that the number of set bits an integer has is the number of 1
s present when written in binary. For example, 21
written in binary is 10101
which has 3 set bits. Also, 1 is not a prime.)
Example 1:
1 | Input: L = 6, R = 10 |
Example 2:
1 | Input: L = 10, R = 15 |
Note:
L, R
will be integers L <= R
in the range [1, 10^6]
.R - L
will be at most 10000.