Embercode
✕
Stacks and QueuesQuick quiz

Trapping rain water

6 questions. Covers Trapping rain water with a Python list as a stack.

Questions 1 to 5 of 6

  1. 1. The stack method pops a bottom bar, and the stack is empty afterwards. What does it do?
  2. 2. What is the total water for the bars {3, 0, 2, 0, 4}?
  3. 3. Put the steps for one popped bar, and the push that follows the pops, in the stack method in the correct order.

    Use the arrows to put the steps in order.

    1. 1.Add width times level, where the level is the lower wall minus the bottom's height.
    2. 2.When the new bar is no longer taller than the top, push the new bar.
    3. 3.If the stack is now empty, stop, because there is no left wall.
    4. 4.Pop the top bar, which is the bottom of a basin.
  4. 4. Put one step of the two-pointer method in the correct order, for the case where the left bar is lower.

    Use the arrows to put the steps in order.

    1. 1.If the left bar is lower, update the left running maximum.
    2. 2.Add the left running maximum minus the left bar's height to the total.
    3. 3.Move the left pointer one step inward.
    4. 4.Compare the left bar with the right bar.
  5. 5. True or false: the stack method stores bar heights on its stack, so it reads them straight off the stack.

3 question(s) left on this page.