Problem Brief
Count Minimum Operations to Reduce Dimensions
OA
See Salesforce online assessment and hiring insights
Given a rectangle with dimensions (h,w). Count the minimum number of operations to make its dimensions reduce to (h1, w1).
An operation is to fold the rectangle paper along any of its side.
Function Description
Complete the function countMinimumOperations in the editor.
countMinimumOperations has the following parameters:
- 1.
int h: the original height of the rectangle - 2.
int w: the original width of the rectangle - 3.
int h1: the reduced height of the rectangle - 4.
int w1: the reduced width of the rectangle
Returns
int: the minimum number of operations required
1Example 1
Input
h = 8, w = 4, h1 = 6, w1 = 1
Output
3
Explanation
(Feel free to lmk if you find anything wrong in this explanation
Many thanks in advance!
:)
To reduce the dimensions from (8,4) to (6,1), the following operations can be performed:
1. Fold along the width to reduce the width from 4 to 2 (1 operation).
2. Fold along the width again to reduce the width from 2 to 1 (1 operation).
3. Fold along the height to reduce the height from 8 to 6 (1 operation).
Therefore, a total of 3 operations are required.
Constraints
Limits and guarantees your solution can rely on.
h1 <= hw1 <= w