Problem · Math
Count Minimum Operations to Reduce Dimensions
Learn this problemProblem statement
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
countMinimumOperations(h: int, w: int, h1: int, w1: int) → int
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
Examples
Example 1
h = 8w = 4h1 = 6w1 = 1return = 3(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
h1 <= hw1 <= wMore Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026