InMobi Interview Question for SDE-2s
- 0of 0 votes
You have a rectangular chocolate bar that consists of width x height square tiles. You can split it into two rectangular pieces by creating a single vertical or horizontal break along tile edges. For example, a 2x2 chocolate bar can be divided into two 2x1 pieces, but it cannot be divided into two pieces, where one of them is 1x1. You can repeat the split operation as many times as you want, each time splitting a single rectangular piece into two rectangular pieces.- poorna.chandra.akp May 19, 2014 in India
Your goal is to create at least one piece which consists of exactly nTiles tiles. Return the minimal number of split operations necessary to reach this goal. If it is impossible, return -1.
Complete the function getMinSplit, which takes in 3 integers as parameters. The first parameter is width of the chocolate, the second is height of the chocolate and third is nTiles, the number of tiles required.
- width will be between 1 and 109, inclusive.
- hight will be between 1 and 109, inclusive.
- nTiles will be between 1 and 109, inclusive.
You can split the chocolate bar into two rectangular pieces 3 x 4 and 2 x 4 by creating a single vertical break. Only one break is necessary.
The chocolate bar consists of exactly 120 tiles.
| Report Duplicate | Flag | PURGE
Open Chat in New Window