X DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Min cut Square
Medium Accuracy: 44.8% Submissions: 975 Points: 4

Given two numbers M and N, which represents the length and breadth of a paper, the task is to cut the paper into squares of any size and find the minimum number of squares that can be cut from the paper.

Example 1:

Input: M = 36, N = 30
Output: 5
Explanation:
3 (squares of size 12x12) +
2 (squares of size 18x18)

Example 2:

Input: M = 4, N = 5
Output: 5
Explanation:
1 (squares of size 4x4) +
4 (squares of size 1x1)

You don't need to read input or print anything. Complete the function minCut() which takes M and N as input parameters and returns the integer value

Expected Time Complexity: O(M*N)
Expected Auxiliary Space: O(M*N)

Constraints:
1 ≤ M, N ≤ 102

We are replacing the old Disqus forum with the new Discussions section given below.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

My Submissions:  