Identical Splitting in a rectangular grid
Given a rectangular grid NxM dimensions, the task is to find the minimum number of cuts required to break the given rectangular grid into a square of size 1×1.
Input: N = 4, M = 4
Input: N = 2, M = 1
The above images shows the splitting of the rectangular grid. We can observe that every single cut increases the number of rectangles of different dimensions by 1. We will do the splitting until we reach the square of dimension 1×1.
So for the given rectangular dimensions of NxM, the total number of squares of dimensions 1×1 is N*M. Therefore we required N*M – 1 cuts to break the given rectangular dimensions of NxM into squares of dimension 1×1.
Below is the implementation of the above approach:
Time Complexity: O(1)