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 untill 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)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if given two straight lines are identical or not
- Height of Pyramid formed with given Rectangular Box
- Maximum of smallest possible area that can get with exactly k cut of given rectangular
- Find the volume of rectangular right wedge
- Recursive program to insert a star between pair of identical characters
- Beginning BootStrap (Part-2) | Grid System
- Convert a String into a square matrix grid of characters
- Top 8 Python Libraries for Data Visualization
- Complete Interview Preparation With Doubt Assistance - INR 90 Lakh Cashback Pool Offer!!
- Best Books to Learn Data Science for Beginners and Experts
- Top 10 Machine Learning Project Ideas That You Can Implement
- Neuromorphic Computing
- Top 5 Golang Frameworks in 2020
- What is Google Chrome Operating System?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.