FastPrepSimplified Tetris Engine
Problems/Simplified Tetris Engine

Simplified Tetris Engine

DRW logoDRW● HardFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

You are building a simplified Tetris engine for a grid that is 10 columns wide. Pieces enter from the top, fall straight down, and come to rest as soon as any part of the piece touches the bottom of the grid or an already-settled block.

Each piece is rigid, consists of four unit squares, and never rotates. The possible piece types are Q, Z, S, T, I, L, and J. A game state starts with an empty grid.

The input to your function is a comma-separated sequence of piece placements. Each placement is encoded as a piece letter followed by a single-digit integer. The integer is the leftmost column occupied by the piece, using zero-based indexing. After each piece settles, if any row becomes completely full, that row is cleared and every row above it drops down together without changing the internal block pattern within each row.

Return the final height of the remaining settled blocks after all placements in the sequence have been processed.

Function

getFinalHeight(sequence: String) → int

Complete the function getFinalHeight in the editor below.

getFinalHeight has the following parameter:

  • String sequence: a comma-separated sequence of piece placements such as "I0,I4,Q8"

Returns int: the final stack height after processing all placements and clearing all complete rows

Examples

Example 1

sequence = "I0,I4,Q8"return = 1

The three pieces fill the entire bottom row, so that row is cleared. The remaining settled blocks have height 1.

Example 2

sequence = "T1,Z3,I4"return = 4

No row becomes completely full, so nothing is cleared. The final settled structure has height 4.

Example 3

sequence = "Q0,I2,I6,I0,I6,I6,Q2,Q4"return = 3

The first row clears after the early placements, and a later row clears again after additional pieces settle. The final remaining structure has height 3.

Constraints

  • The grid width is always 10.
  • Each placement is one of Q, Z, S, T, I, L, or J, followed by a single-digit zero-based column index.
  • Pieces never rotate and always use the fixed orientations shown in the source prompt.
  • The input sequence is valid, and every placement fits within the board.
  • You may assume no test case produces a final height greater than 100.

More DRW problems

  • Defer Expenses to Preserve BalancePHONE SCREEN · Seen Oct 2026
  • Longest Equal-Frequency SubstringPHONE SCREEN · Seen Oct 2026
  • Minimize Range After Three ChangesPHONE SCREEN · Seen Oct 2026
All DRW interview questionsSee DRW hiring insights
Saved
class Solution {
    public int getFinalHeight(String sequence) {
      // write your code here
    }

}
Checking account…