Connect K with Push-Up Drops

Asked at Jane Street· Screen

Reported by the problem's creator, not verified

Import another question

Build a two-player connection game on a board that is the upper half of the integer grid: columns are any integers (negative allowed) and rows are 0, 1, 2, ... counting up from the bottom. PushConnect() starts with an empty board. The two players are the strings "B" and "R". A drop into a column places the new piece at row 0; if the column already holds pieces, every one of them moves up one row first. Each test drives one PushConnect instance through a sequence of calls and checks every return value.

Examples

  1. Example 1

    Input: init = [], operations = [["drop",["B",0]],["drop",["R",0]],["column",[0]],["drop",["B",5]],["column",[5]],["column",[2]],["drop",["B",0]],["column",[0]],["drop",["R",-1]],["column",[-1]]]

    Output: [1,2,"RB",1,"B","",3,"BRB",1,"R"]

    Explanation: Dropping R into column 0 pushes the lone B up, so column 0 reads RB from the bottom. A third drop gives BRB. Column 2 never received a piece, so it reads as an empty string.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.

Connect K with Push-Up Drops