Facebook coderpadder interview question

Print a grid for a given row, column, and array of the height of the ship. The constraint is that do not start with the grid[0][0], it must be RANDOMLY placed.

function: createGrid(int row, int col, int[] shipHeight) { }

Note: calculate row and column randomly based upon the given size and also the direction must be random vertical/horizontal. There can be multiple possibilities to generate a grid having said that all the heights of the ship must be placed.

input : 8, 8, [2, 3, 4]

output :
0 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 ---- > this has height 3
1 1 1 1 0 0 0 0 -----> this has height 4
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
column 1 has height 2

Comments (4)