Practice Number of Pairs of Interchangeable Rectangles
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Number of Pairs of Interchangeable Rectangles
Problem Statement
You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle. Two rectangles i and j (i < j) are considered interchangeable if they have the same width-to-height ratio. More formally, two rectangles are interchangeable if widthi/heighti == widthj/heightj (using decimal division, not integer division). Return the number of pairs of interchangeable rectangles in rectangles.
Source: Number of Pairs of Interchangeable Rectangles on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
rectangles = [[4,8],[3,6],[10,20],[15,30]]
6
# Example 2
rectangles = [[4,5],[7,8]]
0
Constraints
Related LeetCode Problems
Practice more problems similar to Number of Pairs of Interchangeable Rectangles.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.