Company: Flipkart

Difficulty: medium

Problem Statement

Sliding Tile Board Simulation A 4 x 4 board holds tiles. Every cell is either empty, written as 0 , or holds a tile whose value is a power of two ( 2 , 4 , 8 , 16 , ...). A sequence of operations is applied to the board. Each operation is one of L , R , U , D , meaning the tiles slide left, right, up or down. One operation is resolved independently for each of the four lines that run along the direction of travel — the four rows for L and R , the four columns for U and D — as follows. Take the line's tiles in order, starting from the cell nearest the edge the tiles are travelling toward, and ignore its empty cells. Walk that list from the front: If the current tile and the next one hold the same value, they combine into a single tile holding their sum. Both of the original tiles are consumed; a tile produced by a combination cannot combine again during the same operation. Otherwise the current tile survives unchanged. The resulting tiles are then packed against the edge the tiles

More Flipkart OA questionsInterview experiences