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)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Height of Pyramid formed with given Rectangular Box
- Find the volume of rectangular right wedge
- Maximum of smallest possible area that can get with exactly k cut of given rectangular
- Check if given two straight lines are identical or not
- 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
- Python vs Java - Who Will Win the Battle in 2020?
- Top 10 Kali Linux Tools For Hacking
- 13 Mistakes To Avoid During Technical Interview
- How to Start a Career in Software Testing - A Complete Guide!
- Top 10 Data Science Skills to Learn in 2020
- Count of all pairs in an Array with minimum absolute difference
- Minimum cost to convert given string to consist of only vowels
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.