Green Bricks Interview Question for Software Engineer / Developers
- 0of 0 votes
AnswerGreen Bricks asked this question for the post of project leader for their upcoming project.
- John May 31, 2012 in United States for 1 alpha
project engineer has to be in java.
green bricks also offered attractive salary.
the problem was as follows:
Given a set of figures and a board (a 2D array), you are required to figure out if all the figures can be placed on the board such that no two figures overlap each other. A figure can be of any shape and is represented using a matrix of 0s and 1s. The 1s in the matrix indicate the solid part that makes the figure.
Note:
Overlapping of 0s of figure A with 1s and 0s of figure B is allowed.
The figures provided are to be fitted as is without any rotation.
There is only one figure per matrix.
The matrix describing the figure will not have any empty row or column.
Input specification:
The first line contains two integers M and N (0<=50 and 0<=50), the dimensions of the board. The board is empty at the start.
The second line contains an integer F (0<=F<=10), indicating the number of figures followed by F figures.
Each figure has two integers R and C, the dimensions of the matrix containing the figure followed by R lines containing C integers 0's or 1's separated by a space.
Output specification:
If all the given figures fit onto the board then print YES followed by the number of empty cells on the board, separated by a space. If all the pieces cannot be fitted on the board together then print NO.
Sample Input and Output:
Input:
4 4
3
1 1
1
4 3
0 0 1
1 1 1
0 0 1
0 1 1
4 3
1 1 1
1 0 0
1 1 1
1 0 0
Output:
YES 0
this was the sample input output case.
you have to make the program for this which should also work on the following test cases.
Test Case 1:
4 4
3
1 1
1
4 3
0 0 1
1 1 1
0 0 1
0 1 1
4 3
1 1 1
1 0 0
1 1 1
1 0 0
Test Case 2:
4 4
2
4 4
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
4 4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Test Case 3:
8 8
8
2 2
1 1
1 1
2 2
1 1
1 1
2 2
1 1
1 1
2 2
1 1
1 1
2 2
1 1
1 1
2 4
1 1 1 1
1 1 1 1
4 4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
4 8
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0
you have to figure out the answers.
regards,
john| Report Duplicate | Flag | PURGE
Green Bricks Software Engineer / Developer Java
Country: United States
Interview Type: Written Test
I'll admit I'm totally stumped. Brute-force search is the best I can do here.
- Anonymous June 14, 2012