bowang0911/leetcode huggingface dataset:
Find Array Given Subset Sums

You are given an integer `n` representing the length of an unknown array that you are trying to recover. You are also given an array `sums` containing the values of all `2n` **subset sums** of the unknown array (in no particular order).

Return _the array_ `ans` _of length_ `n` _representing the unknown array. If **multiple** answers exist, return **any** of them_.

An array `sub` is a **subset** of an array `arr` if `sub` can be obtained from `arr` by deleting some (possibly zero or all) elements of `arr`. The sum of the elements in `sub` is one possible **subset sum** of `arr`. The sum of an empty array is considered to be `0`.

**Note:** Test cases are generated such that there will **always** be at least one correct answer.

**Example 1:**

**Input:** n = 3, sums = \[-3,-2,-1,0,0,1,2,3\]
**Output:** \[1,2,-3\]
**Explanation:** \[1,2,-3\] is able to achieve the given subset sums:
- \[\]: sum is 0
- \[1\]: sum is 1
- \[2\]: sum is 2
- \[1,2\]: sum is 3
- \[-3\]: sum is -3
- \[1,-3\]: sum is -2
- \[2,-3\]: sum is -1
- \[1,2,-3\]: sum is 0
Note that any permutation of \[1,2,-3\] and also any permutation of \[-1,-2,3\] will also be accepted.

**Example 2:**

**Input:** n = 2, sums = \[0,0,0,0\]
**Output:** \[0,0\]
**Explanation:** The only correct answer is \[0,0\].

**Example 3:**

**Input:** n = 4, sums = \[0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8\]
**Output:** \[0,-1,4,5\]
**Explanation:** \[0,-1,4,5\] is able to achieve the given subset sums.

**Constraints:**

*   `1 <= n <= 15`
*   `sums.length == 2n`
*   `-104 <= sums[i] <= 104`
Widest Pair of Indices With Equal Range Sum

You are given two **0-indexed** binary arrays `nums1` and `nums2`. Find the **widest** pair of indices `(i, j)` such that `i <= j` and `nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]`.

The **widest** pair of indices is the pair with the **largest** **distance** between `i` and `j`. The **distance** between a pair of indices is defined as `j - i + 1`.

Return _the **distance** of the **widest** pair of indices. If no pair of indices meets the conditions, return_ `0`.

**Example 1:**

**Input:** nums1 = \[1,1,0,1\], nums2 = \[0,1,1,0\]
**Output:** 3
**Explanation:**
If i = 1 and j = 3:
nums1\[1\] + nums1\[2\] + nums1\[3\] = 1 + 0 + 1 = 2.
nums2\[1\] + nums2\[2\] + nums2\[3\] = 1 + 1 + 0 = 2.
The distance between i and j is j - i + 1 = 3 - 1 + 1 = 3.

**Example 2:**

**Input:** nums1 = \[0,1\], nums2 = \[1,1\]
**Output:** 1
**Explanation:**
If i = 1 and j = 1:
nums1\[1\] = 1.
nums2\[1\] = 1.
The distance between i and j is j - i + 1 = 1 - 1 + 1 = 1.

**Example 3:**

**Input:** nums1 = \[0\], nums2 = \[1\]
**Output:** 0
**Explanation:**
There are no pairs of indices that meet the requirements.

**Constraints:**

*   `n == nums1.length == nums2.length`
*   `1 <= n <= 105`
*   `nums1[i]` is either `0` or `1`.
*   `nums2[i]` is either `0` or `1`.
Minimum Difference Between Highest and Lowest of K Scores

You are given a **0-indexed** integer array `nums`, where `nums[i]` represents the score of the `ith` student. You are also given an integer `k`.

Pick the scores of any `k` students from the array so that the **difference** between the **highest** and the **lowest** of the `k` scores is **minimized**.

Return _the **minimum** possible difference_.

**Example 1:**

**Input:** nums = \[90\], k = 1
**Output:** 0
**Explanation:** There is one way to pick score(s) of one student:
- \[**90**\]. The difference between the highest and lowest score is 90 - 90 = 0.
The minimum possible difference is 0.

**Example 2:**

**Input:** nums = \[9,4,1,7\], k = 2
**Output:** 2
**Explanation:** There are six ways to pick score(s) of two students:
- \[**9**,**4**,1,7\]. The difference between the highest and lowest score is 9 - 4 = 5.
- \[**9**,4,**1**,7\]. The difference between the highest and lowest score is 9 - 1 = 8.
- \[**9**,4,1,**7**\]. The difference between the highest and lowest score is 9 - 7 = 2.
- \[9,**4**,**1**,7\]. The difference between the highest and lowest score is 4 - 1 = 3.
- \[9,**4**,1,**7**\]. The difference between the highest and lowest score is 7 - 4 = 3.
- \[9,4,**1**,**7**\]. The difference between the highest and lowest score is 7 - 1 = 6.
The minimum possible difference is 2.

**Constraints:**

*   `1 <= k <= nums.length <= 1000`
*   `0 <= nums[i] <= 105`
Find the Kth Largest Integer in the Array

You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros.

Return _the string that represents the_ `kth` _**largest integer** in_ `nums`.

**Note**: Duplicate numbers should be counted distinctly. For example, if `nums` is `[ "1 ", "2 ", "2 "]`, `"2 "` is the first largest integer, `"2 "` is the second-largest integer, and `"1 "` is the third-largest integer.

**Example 1:**

**Input:** nums = \[ "3 ", "6 ", "7 ", "10 "\], k = 4
**Output:**  "3 "
**Explanation:**
The numbers in nums sorted in non-decreasing order are \[ "3 ", "6 ", "7 ", "10 "\].
The 4th largest integer in nums is  "3 ".

**Example 2:**

**Input:** nums = \[ "2 ", "21 ", "12 ", "1 "\], k = 3
**Output:**  "2 "
**Explanation:**
The numbers in nums sorted in non-decreasing order are \[ "1 ", "2 ", "12 ", "21 "\].
The 3rd largest integer in nums is  "2 ".

**Example 3:**

**Input:** nums = \[ "0 ", "0 "\], k = 2
**Output:**  "0 "
**Explanation:**
The numbers in nums sorted in non-decreasing order are \[ "0 ", "0 "\].
The 2nd largest integer in nums is  "0 ".

**Constraints:**

*   `1 <= k <= nums.length <= 104`
*   `1 <= nums[i].length <= 100`
*   `nums[i]` consists of only digits.
*   `nums[i]` will not have any leading zeros.
Minimum Number of Work Sessions to Finish the Tasks

There are `n` tasks assigned to you. The task times are represented as an integer array `tasks` of length `n`, where the `ith` task takes `tasks[i]` hours to finish. A **work session** is when you work for **at most** `sessionTime` consecutive hours and then take a break.

You should finish the given tasks in a way that satisfies the following conditions:

*   If you start a task in a work session, you must complete it in the **same** work session.
*   You can start a new task **immediately** after finishing the previous one.
*   You may complete the tasks in **any order**.

Given `tasks` and `sessionTime`, return _the **minimum** number of **work sessions** needed to finish all the tasks following the conditions above._

The tests are generated such that `sessionTime` is **greater** than or **equal** to the **maximum** element in `tasks[i]`.

**Example 1:**

**Input:** tasks = \[1,2,3\], sessionTime = 3
**Output:** 2
**Explanation:** You can finish the tasks in two work sessions.
- First work session: finish the first and the second tasks in 1 + 2 = 3 hours.
- Second work session: finish the third task in 3 hours.

**Example 2:**

**Input:** tasks = \[3,1,3,1,1\], sessionTime = 8
**Output:** 2
**Explanation:** You can finish the tasks in two work sessions.
- First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.
- Second work session: finish the last task in 1 hour.

**Example 3:**

**Input:** tasks = \[1,2,3,4,5\], sessionTime = 15
**Output:** 1
**Explanation:** You can finish all the tasks in one work session.

**Constraints:**

*   `n == tasks.length`
*   `1 <= n <= 14`
*   `1 <= tasks[i] <= 10`
*   `max(tasks[i]) <= sessionTime <= 15`
Number of Unique Good Subsequences

You are given a binary string `binary`. A **subsequence** of `binary` is considered **good** if it is **not empty** and has **no leading zeros** (with the exception of `"0 "`).

Find the number of **unique good subsequences** of `binary`.

*   For example, if `binary = "001 "`, then all the **good** subsequences are `[ "0 ", "0 ", "1 "]`, so the **unique** good subsequences are `"0 "` and `"1 "`. Note that subsequences `"00 "`, `"01 "`, and `"001 "` are not good because they have leading zeros.

Return _the number of **unique good subsequences** of_ `binary`. Since the answer may be very large, return it **modulo** `109 + 7`.

A **subsequence** is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

**Example 1:**

**Input:** binary =  "001 "
**Output:** 2
**Explanation:** The good subsequences of binary are \[ "0 ",  "0 ",  "1 "\].
The unique good subsequences are  "0 " and  "1 ".

**Example 2:**

**Input:** binary =  "11 "
**Output:** 2
**Explanation:** The good subsequences of binary are \[ "1 ",  "1 ",  "11 "\].
The unique good subsequences are  "1 " and  "11 ".

**Example 3:**

**Input:** binary =  "101 "
**Output:** 5
**Explanation:** The good subsequences of binary are \[ "1 ",  "0 ",  "1 ",  "10 ",  "11 ",  "101 "\]. 
The unique good subsequences are  "0 ",  "1 ",  "10 ",  "11 ", and  "101 ".

**Constraints:**

*   `1 <= binary.length <= 105`
*   `binary` consists of only `'0'`s and `'1'`s.
Maximum Number of People That Can Be Caught in Tag

You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are "it ", and people who are not "it ". The people who are "it " want to catch as many people as possible who are not "it ".

You are given a **0-indexed** integer array `team` containing only zeros (denoting people who are **not** "it ") and ones (denoting people who are "it "), and an integer `dist`. A person who is "it " at index `i` can catch any **one** person whose index is in the range `[i - dist, i + dist]` (**inclusive**) and is **not** "it ".

Return _the **maximum** number of people that the people who are "it " can catch_.

**Example 1:**

**Input:** team = \[0,1,0,1,0\], dist = 3
**Output:** 2
**Explanation:**
The person who is  "it " at index 1 can catch people in the range \[i-dist, i+dist\] = \[1-3, 1+3\] = \[-2, 4\].
They can catch the person who is not  "it " at index 2.
The person who is  "it " at index 3 can catch people in the range \[i-dist, i+dist\] = \[3-3, 3+3\] = \[0, 6\].
They can catch the person who is not  "it " at index 0.
The person who is not  "it " at index 4 will not be caught because the people at indices 1 and 3 are already catching one person.

**Example 2:**

**Input:** team = \[1\], dist = 1
**Output:** 0
**Explanation:**
There are no people who are not  "it " to catch.

**Example 3:**

**Input:** team = \[0\], dist = 1
**Output:** 0
**Explanation:**
There are no people who are  "it " to catch people.

**Constraints:**

*   `1 <= team.length <= 105`
*   `0 <= team[i] <= 1`
*   `1 <= dist <= team.length`
Find the Middle Index in Array

Given a **0-indexed** integer array `nums`, find the **leftmost** `middleIndex` (i.e., the smallest amongst all the possible ones).

A `middleIndex` is an index where `nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1]`.

If `middleIndex == 0`, the left side sum is considered to be `0`. Similarly, if `middleIndex == nums.length - 1`, the right side sum is considered to be `0`.

Return _the **leftmost**_ `middleIndex` _that satisfies the condition, or_ `-1` _if there is no such index_.

**Example 1:**

**Input:** nums = \[2,3,-1,8,4\]
**Output:** 3
**Explanation:** The sum of the numbers before index 3 is: 2 + 3 + -1 = 4
The sum of the numbers after index 3 is: 4 = 4

**Example 2:**

**Input:** nums = \[1,-1,4\]
**Output:** 2
**Explanation:** The sum of the numbers before index 2 is: 1 + -1 = 0
The sum of the numbers after index 2 is: 0

**Example 3:**

**Input:** nums = \[2,5\]
**Output:** -1
**Explanation:** There is no valid middleIndex.

**Constraints:**

*   `1 <= nums.length <= 100`
*   `-1000 <= nums[i] <= 1000`

**Note:** This question is the same as 724: [https://leetcode.com/problems/find-pivot-index/](https://leetcode.com/problems/find-pivot-index/)
Find All Groups of Farmland

You are given a **0-indexed** `m x n` binary matrix `land` where a `0` represents a hectare of forested land and a `1` represents a hectare of farmland.

To keep the land organized, there are designated rectangular areas of hectares that consist **entirely** of farmland. These rectangular areas are called **groups**. No two groups are adjacent, meaning farmland in one group is **not** four-directionally adjacent to another farmland in a different group.

`land` can be represented by a coordinate system where the top left corner of `land` is `(0, 0)` and the bottom right corner of `land` is `(m-1, n-1)`. Find the coordinates of the top left and bottom right corner of each **group** of farmland. A **group** of farmland with a top left corner at `(r1, c1)` and a bottom right corner at `(r2, c2)` is represented by the 4-length array `[r1, c1, r2, c2].`

Return _a 2D array containing the 4-length arrays described above for each **group** of farmland in_ `land`_. If there are no groups of farmland, return an empty array. You may return the answer in **any order**_.

**Example 1:**

**Input:** land = \[\[1,0,0\],\[0,1,1\],\[0,1,1\]\]
**Output:** \[\[0,0,0,0\],\[1,1,2,2\]\]
**Explanation:**
The first group has a top left corner at land\[0\]\[0\] and a bottom right corner at land\[0\]\[0\].
The second group has a top left corner at land\[1\]\[1\] and a bottom right corner at land\[2\]\[2\].

**Example 2:**

**Input:** land = \[\[1,1\],\[1,1\]\]
**Output:** \[\[0,0,1,1\]\]
**Explanation:**
The first group has a top left corner at land\[0\]\[0\] and a bottom right corner at land\[1\]\[1\].

**Example 3:**

**Input:** land = \[\[0\]\]
**Output:** \[\]
**Explanation:**
There are no groups of farmland.

**Constraints:**

*   `m == land.length`
*   `n == land[i].length`
*   `1 <= m, n <= 300`
*   `land` consists of only `0`'s and `1`'s.
*   Groups of farmland are **rectangular** in shape.
The Number of Good Subsets

You are given an integer array `nums`. We call a subset of `nums` **good** if its product can be represented as a product of one or more **distinct prime** numbers.

*   For example, if `nums = [1, 2, 3, 4]`:
    *   `[2, 3]`, `[1, 2, 3]`, and `[1, 3]` are **good** subsets with products `6 = 2*3`, `6 = 2*3`, and `3 = 3` respectively.
    *   `[1, 4]` and `[4]` are not **good** subsets with products `4 = 2*2` and `4 = 2*2` respectively.

Return _the number of different **good** subsets in_ `nums` _**modulo**_ `109 + 7`.

A **subset** of `nums` is any array that can be obtained by deleting some (possibly none or all) elements from `nums`. Two subsets are different if and only if the chosen indices to delete are different.

**Example 1:**

**Input:** nums = \[1,2,3,4\]
**Output:** 6
**Explanation:** The good subsets are:
- \[1,2\]: product is 2, which is the product of distinct prime 2.
- \[1,2,3\]: product is 6, which is the product of distinct primes 2 and 3.
- \[1,3\]: product is 3, which is the product of distinct prime 3.
- \[2\]: product is 2, which is the product of distinct prime 2.
- \[2,3\]: product is 6, which is the product of distinct primes 2 and 3.
- \[3\]: product is 3, which is the product of distinct prime 3.

**Example 2:**

**Input:** nums = \[4,2,3,15\]
**Output:** 5
**Explanation:** The good subsets are:
- \[2\]: product is 2, which is the product of distinct prime 2.
- \[2,3\]: product is 6, which is the product of distinct primes 2 and 3.
- \[2,15\]: product is 30, which is the product of distinct primes 2, 3, and 5.
- \[3\]: product is 3, which is the product of distinct prime 3.
- \[15\]: product is 15, which is the product of distinct primes 3 and 5.

**Constraints:**

*   `1 <= nums.length <= 105`
*   `1 <= nums[i] <= 30`
The Number of Weak Characters in the Game

You are playing a game that contains multiple characters, and each of the characters has **two** main properties: **attack** and **defense**. You are given a 2D integer array `properties` where `properties[i] = [attacki, defensei]` represents the properties of the `ith` character in the game.

A character is said to be **weak** if any other character has **both** attack and defense levels **strictly greater** than this character's attack and defense levels. More formally, a character `i` is said to be **weak** if there exists another character `j` where `attackj > attacki` and `defensej > defensei`.

Return _the number of **weak** characters_.

**Example 1:**

**Input:** properties = \[\[5,5\],\[6,3\],\[3,6\]\]
**Output:** 0
**Explanation:** No character has strictly greater attack and defense than the other.

**Example 2:**

**Input:** properties = \[\[2,2\],\[3,3\]\]
**Output:** 1
**Explanation:** The first character is weak because the second character has a strictly greater attack and defense.

**Example 3:**

**Input:** properties = \[\[1,5\],\[10,4\],\[4,3\]\]
**Output:** 1
**Explanation:** The third character is weak because the second character has a strictly greater attack and defense.

**Constraints:**

*   `2 <= properties.length <= 105`
*   `properties[i].length == 2`
*   `1 <= attacki, defensei <= 105`
First Day Where You Have Been in All the Rooms

There are `n` rooms you need to visit, labeled from `0` to `n - 1`. Each day is labeled, starting from `0`. You will go in and visit one room a day.

Initially on day `0`, you visit room `0`. The **order** you visit the rooms for the coming days is determined by the following **rules** and a given **0-indexed** array `nextVisit` of length `n`:

*   Assuming that on a day, you visit room `i`,
*   if you have been in room `i` an **odd** number of times (**including** the current visit), on the **next** day you will visit a room with a **lower or equal room number** specified by `nextVisit[i]` where `0 <= nextVisit[i] <= i`;
*   if you have been in room `i` an **even** number of times (**including** the current visit), on the **next** day you will visit room `(i + 1) mod n`.

Return _the label of the **first** day where you have been in **all** the rooms_. It can be shown that such a day exists. Since the answer may be very large, return it **modulo** `109 + 7`.

**Example 1:**

**Input:** nextVisit = \[0,0\]
**Output:** 2
**Explanation:**
- On day 0, you visit room 0. The total times you have been in room 0 is 1, which is odd.
  On the next day you will visit room nextVisit\[0\] = 0
- On day 1, you visit room 0, The total times you have been in room 0 is 2, which is even.
  On the next day you will visit room (0 + 1) mod 2 = 1
- On day 2, you visit room 1. This is the first day where you have been in all the rooms.

**Example 2:**

**Input:** nextVisit = \[0,0,2\]
**Output:** 6
**Explanation:**
Your room visiting order for each day is: \[0,0,1,0,0,1,2,...\].
Day 6 is the first day where you have been in all the rooms.

**Example 3:**

**Input:** nextVisit = \[0,1,2,0\]
**Output:** 6
**Explanation:**
Your room visiting order for each day is: \[0,0,1,1,2,2,3,...\].
Day 6 is the first day where you have been in all the rooms.

**Constraints:**

*   `n == nextVisit.length`
*   `2 <= n <= 105`
*   `0 <= nextVisit[i] <= i`
GCD Sort of an Array

You are given an integer array `nums`, and you can perform the following operation **any** number of times on `nums`:

*   Swap the positions of two elements `nums[i]` and `nums[j]` if `gcd(nums[i], nums[j]) > 1` where `gcd(nums[i], nums[j])` is the **greatest common divisor** of `nums[i]` and `nums[j]`.

Return `true` _if it is possible to sort_ `nums` _in **non-decreasing** order using the above swap method, or_ `false` _otherwise._

**Example 1:**

**Input:** nums = \[7,21,3\]
**Output:** true
**Explanation:** We can sort \[7,21,3\] by performing the following operations:
- Swap 7 and 21 because gcd(7,21) = 7. nums = \[**21**,**7**,3\]
- Swap 21 and 3 because gcd(21,3) = 3. nums = \[**3**,7,**21**\]

**Example 2:**

**Input:** nums = \[5,2,6,2\]
**Output:** false
**Explanation:** It is impossible to sort the array because 5 cannot be swapped with any other element.

**Example 3:**

**Input:** nums = \[10,5,9,3,15\]
**Output:** true
We can sort \[10,5,9,3,15\] by performing the following operations:
- Swap 10 and 15 because gcd(10,15) = 5. nums = \[**15**,5,9,3,**10**\]
- Swap 15 and 3 because gcd(15,3) = 3. nums = \[**3**,5,9,**15**,10\]
- Swap 10 and 15 because gcd(10,15) = 5. nums = \[3,5,9,**10**,**15**\]

**Constraints:**

*   `1 <= nums.length <= 3 * 104`
*   `2 <= nums[i] <= 105`
Smallest Greater Multiple Made of Two Digits

Given three integers, `k`, `digit1`, and `digit2`, you want to find the **smallest** integer that is:

*   **Larger** than `k`,
*   A **multiple** of `k`, and
*   Comprised of **only** the digits `digit1` and/or `digit2`.

Return _the **smallest** such integer. If no such integer exists or the integer exceeds the limit of a signed 32-bit integer (_`231 - 1`_), return_ `-1`.

**Example 1:**

**Input:** k = 2, digit1 = 0, digit2 = 2
**Output:** 20
**Explanation:**
20 is the first integer larger than 2, a multiple of 2, and comprised of only the digits 0 and/or 2.

**Example 2:**

**Input:** k = 3, digit1 = 4, digit2 = 2
**Output:** 24
**Explanation:**
24 is the first integer larger than 3, a multiple of 3, and comprised of only the digits 4 and/or 2.

**Example 3:**

**Input:** k = 2, digit1 = 0, digit2 = 0
**Output:** -1
**Explanation:**
No integer meets the requirements so return -1.

**Constraints:**

*   `1 <= k <= 1000`
*   `0 <= digit1 <= 9`
*   `0 <= digit2 <= 9`
Reverse Prefix of Word

Given a **0-indexed** string `word` and a character `ch`, **reverse** the segment of `word` that starts at index `0` and ends at the index of the **first occurrence** of `ch` (**inclusive**). If the character `ch` does not exist in `word`, do nothing.

*   For example, if `word = "abcdefd "` and `ch = "d "`, then you should **reverse** the segment that starts at `0` and ends at `3` (**inclusive**). The resulting string will be `"dcbaefd "`.

Return _the resulting string_.

**Example 1:**

**Input:** word =  "abcdefd ", ch =  "d "
**Output:**  "dcbaefd "
**Explanation:** The first occurrence of  "d " is at index 3. 
Reverse the part of word from 0 to 3 (inclusive), the resulting string is  "dcbaefd ".

**Example 2:**

**Input:** word =  "xyxzxe ", ch =  "z "
**Output:**  "zxyxxe "
**Explanation:** The first and only occurrence of  "z " is at index 3.
Reverse the part of word from 0 to 3 (inclusive), the resulting string is  "zxyxxe ".

**Example 3:**

**Input:** word =  "abcd ", ch =  "z "
**Output:**  "abcd "
**Explanation:**  "z " does not exist in word.
You should not do any reverse operation, the resulting string is  "abcd ".

**Constraints:**

*   `1 <= word.length <= 250`
*   `word` consists of lowercase English letters.
*   `ch` is a lowercase English letter.
Number of Pairs of Interchangeable Rectangles

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`.

**Example 1:**

**Input:** rectangles = \[\[4,8\],\[3,6\],\[10,20\],\[15,30\]\]
**Output:** 6
**Explanation:** The following are the interchangeable pairs of rectangles by index (0-indexed):
- Rectangle 0 with rectangle 1: 4/8 == 3/6.
- Rectangle 0 with rectangle 2: 4/8 == 10/20.
- Rectangle 0 with rectangle 3: 4/8 == 15/30.
- Rectangle 1 with rectangle 2: 3/6 == 10/20.
- Rectangle 1 with rectangle 3: 3/6 == 15/30.
- Rectangle 2 with rectangle 3: 10/20 == 15/30.

**Example 2:**

**Input:** rectangles = \[\[4,5\],\[7,8\]\]
**Output:** 0
**Explanation:** There are no interchangeable pairs of rectangles.

**Constraints:**

*   `n == rectangles.length`
*   `1 <= n <= 105`
*   `rectangles[i].length == 2`
*   `1 <= widthi, heighti <= 105`