Copied to Clipboard
Squares in Rectangle
Easy Accuracy: 48.39% Submissions: 277 Points: 2

Given a rectangle of size L x B. Find the minimum number of squares required to fill the rectangle such that no two square overlaps.

Example 1:

Input: L = 4, B = 5
Output: 5
Explaination: One 4*4 square and four 1*1 
squares are required.

Example 2:

Input: L = 2, B = 4
Output: 2
Explaintion: Two 2*2 squares are enough to 
fill the rectangle.

Your Task:
You do not need to read input or print anything. Your task is to complete the  function minSquares() which takes L and B as input parameters and returns minimum number of squares required to fill the rectangle. Return the answer modulo 109 + 7.

Expected Time Complexity: O(log(max(L, B)))
Expected Auxiliary Space: O(1)

1 ≤ L, B ≤ 1010   

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


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


All Submissions

My Submissions:

Login to access your submissions.

Squares in Rectangle

Output Window