We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you haven't solved it yet - the key here is: a supply drop can cover 4 blocks. Therefore if the grid is 2x2, 1 suppy drop is enough. But if the grid is 3x2?
1 suppy drop will cover 2x2 portion of the grid but still there is 1x2 part and you need a supply drop there anyway. Same as how many you would need in a 4x2 grid.
Similarly if the region was 3x3 you would need as much drops as you would need in a 4x4 grid. Otherwise some blocks would be left empty.
So for simplicity of calculation we increment the odd integer to it's nearest bigger even (yes, that means odd+1) and then multiply n and m and divide it by 4. That's how many supply drops we must need to cover all the blocks.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Army Game
You are viewing a single comment's thread. Return to all comments →
If you haven't solved it yet - the key here is: a supply drop can cover 4 blocks. Therefore if the grid is 2x2, 1 suppy drop is enough. But if the grid is 3x2?
1 suppy drop will cover 2x2 portion of the grid but still there is 1x2 part and you need a supply drop there anyway. Same as how many you would need in a 4x2 grid.
Similarly if the region was 3x3 you would need as much drops as you would need in a 4x4 grid. Otherwise some blocks would be left empty.
So for simplicity of calculation we increment the odd integer to it's nearest bigger even (yes, that means odd+1) and then multiply n and m and divide it by 4. That's how many supply drops we must need to cover all the blocks.