Trains the technique from
LeetCode 2001Number of Pairs of Interchangeable RectanglesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A glazier's stock is given as rectangles, where rectangles[i] is [width, height].
Two panes are the same shape when their width divided by their height comes to the same value.
Return how many pairs of panes in the stock are the same shape.
Example 1
The first two both reduce to 2 by 3, and the next two both reduce to 3 by 2, giving one pair from each group. The last pane is on its own.
Example 2
All six panes reduce to 1 by 7, so every one of the fifteen pairs matches.
Example 3
Turning a pane on its side gives a different proportion, so these two are not the same shape.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def interchangeable_rectangles(rectangles: list[list[int]]) -> int:public long interchangeableRectangles(int[][] rectangles)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.