Company: hirepro_sde_intern_offcampus
Difficulty: medium
Rakesh is playing a game called "2048". In this game, a 4x4 cell grid is given, where each cell can either be empty (denoted by having the value 0), or can have a value of 2 k where k is any number between 1 and 11. The game aims to win by arriving at a value of 2048 by repeatedly moving in one of four directions: up (U), down (D), right (R), or left (L). When one of these four direction buttons is pressed, all the cells in the grid try to move in that direction. During this movement, if any adjacent cells (adjacent in the direction of the movement) have the same value, then they merge and add up. For instance, if there are two adjacent cells in a row with values 4 and 4, and the R button is pressed, the left cell moves Right and gets added to the right cell, and itself becomes empty, so "4 4" becomes "0 8". Similarly "16 16" becomes "0 32", however, "2 4" remains as "2 4" since the values are different and no merging takes place. Alternately, if the adjacent cell is empty, then the va