Week1 (Mar 11)

441. Arranging Coins

Question

You have

n coins and you want to build a staircase with these coins. The staircase consists of
k
rows where the ith row has exactly
i
coins. The last row of the staircase may be incomplete.

Given the integer

n, return the number of complete rows of the staircase you will build.

Hand in homework before Saturday.

107. Binary Tree Level Order Traversal II

Question

Given the

root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).

Hand in homework before Saturday.

957. Prison Cells After N Days

Question

There are

8 prison cells in a row and each cell is either occupied or vacant.

Each day, whether the cell is occupied or vacant changes according to the following rules:

  • If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
  • Otherwise, it becomes vacant.

Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.

You are given an integer array

cells where
cells[i]==1
if the
ith
cell is occupied and
cells[i]==0
if the
ith
cell is vacant, and you are given an integer
n
.

Return the state of the prison after

n days (i.e.,
n
such changes described above).

Hand in homework before Saturday.