Connect K with Push-Up Drops
Asked at Jane Street· Screen
Reported by the problem's creator, not verified
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
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
Rinto column 0 pushes the loneBup, so column 0 readsRBfrom the bottom. A third drop givesBRB. Column 2 never received a piece, so it reads as an empty string.