Simplified Tetris Engine
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.
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
1Example 1
1.2Example 2
4.3Example 3
3.Constraints
Limits and guarantees your solution can rely on.
- The grid width is always
10. - Each placement is one of
Q,Z,S,T,I,L, orJ, 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.