Firstly lets take a look at the criteria of taking an area:

  • You can only occupy some area if the area has height hh and width ww.

  • All cells of the selected area should either be Land or Water.

  • You can select areas multiple times from the grid.

  • Your selected areas can intersect with each other.

Now suppose you have a Grid of size 3*3 and h=2 and w=2.

If this is our grid, how many different area’s we can consider?
1st area = we can consider cells 1,2,4,5 2nd area = we can consider cells 2,3,5,6 3rd area = we can consider cells 4,5,7,8 4th area = we can consider cells 5,6,8,9

so there are 4 different area we can consider.

Now, as we know our areas which we can consider, we just need to take possession of the areas which is valid i.e. all the cells in that area is either ‘L’ or ‘W‘.

Lastly, we may sometimes count a cell to the answer multiple times. So we just need to handle that so that answer contains all distinct cells.


50% Solution Ratio
tasnim07Earliest, May '23
tasnim07Fastest, 0.0s
tasnim07Lightest, 4.9 MB
tasnim07Shortest, 1375B
Toph uses cookies. By continuing you agree to our Cookie Policy.