bowang0911/leetcode huggingface dataset:
Binary Subarrays With Sum

Given a binary array `nums` and an integer `goal`, return _the number of non-empty **subarrays** with a sum_ `goal`.

A **subarray** is a contiguous part of the array.

**Example 1:**

**Input:** nums = \[1,0,1,0,1\], goal = 2
**Output:** 4
**Explanation:** The 4 subarrays are bolded and underlined below:
\[**1,0,1**,0,1\]
\[**1,0,1,0**,1\]
\[1,**0,1,0,1**\]
\[1,0,**1,0,1**\]

**Example 2:**

**Input:** nums = \[0,0,0,0,0\], goal = 0
**Output:** 15

**Constraints:**

*   `1 <= nums.length <= 3 * 104`
*   `nums[i]` is either `0` or `1`.
*   `0 <= goal <= nums.length`
Minimum Falling Path Sum

Given an `n x n` array of integers `matrix`, return _the **minimum sum** of any **falling path** through_ `matrix`.

A **falling path** starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position `(row, col)` will be `(row + 1, col - 1)`, `(row + 1, col)`, or `(row + 1, col + 1)`.

**Example 1:**

**Input:** matrix = \[\[2,1,3\],\[6,5,4\],\[7,8,9\]\]
**Output:** 13
**Explanation:** There are two falling paths with a minimum sum as shown.

**Example 2:**

**Input:** matrix = \[\[-19,57\],\[-40,-5\]\]
**Output:** -59
**Explanation:** The falling path with a minimum sum is shown.

**Constraints:**

*   `n == matrix.length == matrix[i].length`
*   `1 <= n <= 100`
*   `-100 <= matrix[i][j] <= 100`
Beautiful Array

An array `nums` of length `n` is **beautiful** if:

*   `nums` is a permutation of the integers in the range `[1, n]`.
*   For every `0 <= i < j < n`, there is no index `k` with `i < k < j` where `2 * nums[k] == nums[i] + nums[j]`.

Given the integer `n`, return _any **beautiful** array_ `nums` _of length_ `n`. There will be at least one valid answer for the given `n`.

**Example 1:**

**Input:** n = 4
**Output:** \[2,1,4,3\]

**Example 2:**

**Input:** n = 5
**Output:** \[3,1,2,5,4\]

**Constraints:**

*   `1 <= n <= 1000`
Number of Recent Calls

You have a `RecentCounter` class which counts the number of recent requests within a certain time frame.

Implement the `RecentCounter` class:

*   `RecentCounter()` Initializes the counter with zero recent requests.
*   `int ping(int t)` Adds a new request at time `t`, where `t` represents some time in milliseconds, and returns the number of requests that has happened in the past `3000` milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range `[t - 3000, t]`.

It is **guaranteed** that every call to `ping` uses a strictly larger value of `t` than the previous call.

**Example 1:**

**Input**
\[ "RecentCounter ",  "ping ",  "ping ",  "ping ",  "ping "\]
\[\[\], \[1\], \[100\], \[3001\], \[3002\]\]
**Output**
\[null, 1, 2, 3, 3\]

**Explanation**
RecentCounter recentCounter = new RecentCounter();
recentCounter.ping(1);     // requests = \[1\], range is \[-2999,1\], return 1
recentCounter.ping(100);   // requests = \[1, 100\], range is \[-2900,100\], return 2
recentCounter.ping(3001);  // requests = \[1, 100, 3001\], range is \[1,3001\], return 3
recentCounter.ping(3002);  // requests = \[1, 100, 3001, 3002\], range is \[2,3002\], return 3

**Constraints:**

*   `1 <= t <= 109`
*   Each test case will call `ping` with **strictly increasing** values of `t`.
*   At most `104` calls will be made to `ping`.
Shortest Bridge

You are given an `n x n` binary matrix `grid` where `1` represents land and `0` represents water.

An **island** is a 4-directionally connected group of `1`'s not connected to any other `1`'s. There are **exactly two islands** in `grid`.

You may change `0`'s to `1`'s to connect the two islands to form **one island**.

Return _the smallest number of_ `0`_'s you must flip to connect the two islands_.

**Example 1:**

**Input:** grid = \[\[0,1\],\[1,0\]\]
**Output:** 1

**Example 2:**

**Input:** grid = \[\[0,1,0\],\[0,0,0\],\[0,0,1\]\]
**Output:** 2

**Example 3:**

**Input:** grid = \[\[1,1,1,1,1\],\[1,0,0,0,1\],\[1,0,1,0,1\],\[1,0,0,0,1\],\[1,1,1,1,1\]\]
**Output:** 1

**Constraints:**

*   `n == grid.length == grid[i].length`
*   `2 <= n <= 100`
*   `grid[i][j]` is either `0` or `1`.
*   There are exactly two islands in `grid`.
Knight Dialer

The chess knight has a **unique movement**, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an **L**). The possible movements of chess knight are shown in this diagaram:

A chess knight can move as indicated in the chess diagram below:

We have a chess knight and a phone pad as shown below, the knight **can only stand on a numeric cell** (i.e. blue cell).

Given an integer `n`, return how many distinct phone numbers of length `n` we can dial.

You are allowed to place the knight **on any numeric cell** initially and then you should perform `n - 1` jumps to dial a number of length `n`. All jumps should be **valid** knight jumps.

As the answer may be very large, **return the answer modulo** `109 + 7`.

**Example 1:**

**Input:** n = 1
**Output:** 10
**Explanation:** We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.

**Example 2:**

**Input:** n = 2
**Output:** 20
**Explanation:** All the valid number we can dial are \[04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94\]

**Example 3:**

**Input:** n = 3131
**Output:** 136006598
**Explanation:** Please take care of the mod.

**Constraints:**

*   `1 <= n <= 5000`
Stamping The Sequence

You are given two strings `stamp` and `target`. Initially, there is a string `s` of length `target.length` with all `s[i] == '?'`.

In one turn, you can place `stamp` over `s` and replace every letter in the `s` with the corresponding letter from `stamp`.

*   For example, if `stamp = "abc "` and `target = "abcba "`, then `s` is `"????? "` initially. In one turn you can:
    
    *   place `stamp` at index `0` of `s` to obtain `"abc?? "`,
    *   place `stamp` at index `1` of `s` to obtain `"?abc? "`, or
    *   place `stamp` at index `2` of `s` to obtain `"??abc "`.
    
    Note that `stamp` must be fully contained in the boundaries of `s` in order to stamp (i.e., you cannot place `stamp` at index `3` of `s`).

We want to convert `s` to `target` using **at most** `10 * target.length` turns.

Return _an array of the index of the left-most letter being stamped at each turn_. If we cannot obtain `target` from `s` within `10 * target.length` turns, return an empty array.

**Example 1:**

**Input:** stamp =  "abc ", target =  "ababc "
**Output:** \[0,2\]
**Explanation:** Initially s =  "????? ".
- Place stamp at index 0 to get  "abc?? ".
- Place stamp at index 2 to get  "ababc ".
\[1,0,2\] would also be accepted as an answer, as well as some other answers.

**Example 2:**

**Input:** stamp =  "abca ", target =  "aabcaca "
**Output:** \[3,0,1\]
**Explanation:** Initially s =  "??????? ".
- Place stamp at index 3 to get  "???abca ".
- Place stamp at index 0 to get  "abcabca ".
- Place stamp at index 1 to get  "aabcaca ".

**Constraints:**

*   `1 <= stamp.length <= target.length <= 1000`
*   `stamp` and `target` consist of lowercase English letters.
Reorder Data in Log Files

You are given an array of `logs`. Each log is a space-delimited string of words, where the first word is the **identifier**.

There are two types of logs:

*   **Letter-logs**: All words (except the identifier) consist of lowercase English letters.
*   **Digit-logs**: All words (except the identifier) consist of digits.

Reorder these logs so that:

1.  The **letter-logs** come before all **digit-logs**.
2.  The **letter-logs** are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.
3.  The **digit-logs** maintain their relative ordering.

Return _the final order of the logs_.

**Example 1:**

**Input:** logs = \[ "dig1 8 1 5 1 ", "let1 art can ", "dig2 3 6 ", "let2 own kit dig ", "let3 art zero "\]
**Output:** \[ "let1 art can ", "let3 art zero ", "let2 own kit dig ", "dig1 8 1 5 1 ", "dig2 3 6 "\]
**Explanation:**
The letter-log contents are all different, so their ordering is  "art can ",  "art zero ",  "own kit dig ".
The digit-logs have a relative order of  "dig1 8 1 5 1 ",  "dig2 3 6 ".

**Example 2:**

**Input:** logs = \[ "a1 9 2 3 1 ", "g1 act car ", "zo4 4 7 ", "ab1 off key dog ", "a8 act zoo "\]
**Output:** \[ "g1 act car ", "a8 act zoo ", "ab1 off key dog ", "a1 9 2 3 1 ", "zo4 4 7 "\]

**Constraints:**

*   `1 <= logs.length <= 100`
*   `3 <= logs[i].length <= 100`
*   All the tokens of `logs[i]` are separated by a **single** space.
*   `logs[i]` is guaranteed to have an identifier and at least one word after the identifier.
Range Sum of BST

Given the `root` node of a binary search tree and two integers `low` and `high`, return _the sum of values of all nodes with a value in the **inclusive** range_ `[low, high]`.

**Example 1:**

**Input:** root = \[10,5,15,3,7,null,18\], low = 7, high = 15
**Output:** 32
**Explanation:** Nodes 7, 10, and 15 are in the range \[7, 15\]. 7 + 10 + 15 = 32.

**Example 2:**

**Input:** root = \[10,5,15,3,7,13,18,1,null,6\], low = 6, high = 10
**Output:** 23
**Explanation:** Nodes 6, 7, and 10 are in the range \[6, 10\]. 6 + 7 + 10 = 23.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 2 * 104]`.
*   `1 <= Node.val <= 105`
*   `1 <= low <= high <= 105`
*   All `Node.val` are **unique**.
Minimum Area Rectangle

You are given an array of points in the **X-Y** plane `points` where `points[i] = [xi, yi]`.

Return _the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes_. If there is not any such rectangle, return `0`.

**Example 1:**

**Input:** points = \[\[1,1\],\[1,3\],\[3,1\],\[3,3\],\[2,2\]\]
**Output:** 4

**Example 2:**

**Input:** points = \[\[1,1\],\[1,3\],\[3,1\],\[3,3\],\[4,1\],\[4,3\]\]
**Output:** 2

**Constraints:**

*   `1 <= points.length <= 500`
*   `points[i].length == 2`
*   `0 <= xi, yi <= 4 * 104`
*   All the given points are **unique**.
Distinct Subsequences II

Given a string s, return _the number of **distinct non-empty subsequences** of_ `s`. Since the answer may be very large, return it **modulo** `109 + 7`.

A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not.

**Example 1:**

**Input:** s =  "abc "
**Output:** 7
**Explanation:** The 7 distinct subsequences are  "a ",  "b ",  "c ",  "ab ",  "ac ",  "bc ", and  "abc ".

**Example 2:**

**Input:** s =  "aba "
**Output:** 6
**Explanation:** The 6 distinct subsequences are  "a ",  "b ",  "ab ",  "aa ",  "ba ", and  "aba ".

**Example 3:**

**Input:** s =  "aaa "
**Output:** 3
**Explanation:** The 3 distinct subsequences are  "a ",  "aa " and  "aaa ".

**Constraints:**

*   `1 <= s.length <= 2000`
*   `s` consists of lowercase English letters.
Valid Mountain Array

Given an array of integers `arr`, return _`true` if and only if it is a valid mountain array_.

Recall that arr is a mountain array if and only if:

*   `arr.length >= 3`
*   There exists some `i` with `0 < i < arr.length - 1` such that:
    *   `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]`
    *   `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]`

**Example 1:**

**Input:** arr = \[2,1\]
**Output:** false

**Example 2:**

**Input:** arr = \[3,5,5\]
**Output:** false

**Example 3:**

**Input:** arr = \[0,3,2,1\]
**Output:** true

**Constraints:**

*   `1 <= arr.length <= 104`
*   `0 <= arr[i] <= 104`
DI String Match

A permutation `perm` of `n + 1` integers of all the integers in the range `[0, n]` can be represented as a string `s` of length `n` where:

*   `s[i] == 'I'` if `perm[i] < perm[i + 1]`, and
*   `s[i] == 'D'` if `perm[i] > perm[i + 1]`.

Given a string `s`, reconstruct the permutation `perm` and return it. If there are multiple valid permutations perm, return **any of them**.

**Example 1:**

**Input:** s = "IDID"
**Output:** \[0,4,1,3,2\]

**Example 2:**

**Input:** s = "III"
**Output:** \[0,1,2,3\]

**Example 3:**

**Input:** s = "DDI"
**Output:** \[3,2,0,1\]

**Constraints:**

*   `1 <= s.length <= 105`
*   `s[i]` is either `'I'` or `'D'`.
Find the Shortest Superstring

Given an array of strings `words`, return _the smallest string that contains each string in_ `words` _as a substring_. If there are multiple valid strings of the smallest length, return **any of them**.

You may assume that no string in `words` is a substring of another string in `words`.

**Example 1:**

**Input:** words = \[ "alex ", "loves ", "leetcode "\]
**Output:**  "alexlovesleetcode "
**Explanation:** All permutations of  "alex ", "loves ", "leetcode " would also be accepted.

**Example 2:**

**Input:** words = \[ "catg ", "ctaagt ", "gcta ", "ttca ", "atgcatc "\]
**Output:**  "gctaagttcatgcatc "

**Constraints:**

*   `1 <= words.length <= 12`
*   `1 <= words[i].length <= 20`
*   `words[i]` consists of lowercase English letters.
*   All the strings of `words` are **unique**.
Delete Columns to Make Sorted

You are given an array of `n` strings `strs`, all of the same length.

The strings can be arranged such that there is one on each line, making a grid.

*   For example, `strs = [ "abc ", "bce ", "cae "]` can be arranged as follows:

abc
bce
cae

You want to **delete** the columns that are **not sorted lexicographically**. In the above example (**0-indexed**), columns 0 (`'a'`, `'b'`, `'c'`) and 2 (`'c'`, `'e'`, `'e'`) are sorted, while column 1 (`'b'`, `'c'`, `'a'`) is not, so you would delete column 1.

Return _the number of columns that you will delete_.

**Example 1:**

**Input:** strs = \[ "cba ", "daf ", "ghi "\]
**Output:** 1
**Explanation:** The grid looks as follows:
  cba
  daf
  ghi
Columns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.

**Example 2:**

**Input:** strs = \[ "a ", "b "\]
**Output:** 0
**Explanation:** The grid looks as follows:
  a
  b
Column 0 is the only column and is sorted, so you will not delete any columns.

**Example 3:**

**Input:** strs = \[ "zyx ", "wvu ", "tsr "\]
**Output:** 3
**Explanation:** The grid looks as follows:
  zyx
  wvu
  tsr
All 3 columns are not sorted, so you will delete all 3.

**Constraints:**

*   `n == strs.length`
*   `1 <= n <= 100`
*   `1 <= strs[i].length <= 1000`
*   `strs[i]` consists of lowercase English letters.
Minimum Increment to Make Array Unique

You are given an integer array `nums`. In one move, you can pick an index `i` where `0 <= i < nums.length` and increment `nums[i]` by `1`.

Return _the minimum number of moves to make every value in_ `nums` _**unique**_.

The test cases are generated so that the answer fits in a 32-bit integer.

**Example 1:**

**Input:** nums = \[1,2,2\]
**Output:** 1
**Explanation:** After 1 move, the array could be \[1, 2, 3\].

**Example 2:**

**Input:** nums = \[3,2,1,2,1,7\]
**Output:** 6
**Explanation:** After 6 moves, the array could be \[3, 4, 1, 2, 5, 7\].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.

**Constraints:**

*   `1 <= nums.length <= 105`
*   `0 <= nums[i] <= 105`
Validate Stack Sequences

Given two integer arrays `pushed` and `popped` each with distinct values, return `true` _if this could have been the result of a sequence of push and pop operations on an initially empty stack, or_ `false` _otherwise._

**Example 1:**

**Input:** pushed = \[1,2,3,4,5\], popped = \[4,5,3,2,1\]
**Output:** true
**Explanation:** We might do the following sequence:
push(1), push(2), push(3), push(4),
pop() -> 4,
push(5),
pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1

**Example 2:**

**Input:** pushed = \[1,2,3,4,5\], popped = \[4,3,5,1,2\]
**Output:** false
**Explanation:** 1 cannot be popped before 2.

**Constraints:**

*   `1 <= pushed.length <= 1000`
*   `0 <= pushed[i] <= 1000`
*   All the elements of `pushed` are **unique**.
*   `popped.length == pushed.length`
*   `popped` is a permutation of `pushed`.
Most Stones Removed with Same Row or Column

On a 2D plane, we place `n` stones at some integer coordinate points. Each coordinate point may have at most one stone.

A stone can be removed if it shares either **the same row or the same column** as another stone that has not been removed.

Given an array `stones` of length `n` where `stones[i] = [xi, yi]` represents the location of the `ith` stone, return _the largest possible number of stones that can be removed_.

**Example 1:**

**Input:** stones = \[\[0,0\],\[0,1\],\[1,0\],\[1,2\],\[2,1\],\[2,2\]\]
**Output:** 5
**Explanation:** One way to remove 5 stones is as follows:
1. Remove stone \[2,2\] because it shares the same row as \[2,1\].
2. Remove stone \[2,1\] because it shares the same column as \[0,1\].
3. Remove stone \[1,2\] because it shares the same row as \[1,0\].
4. Remove stone \[1,0\] because it shares the same column as \[0,0\].
5. Remove stone \[0,1\] because it shares the same row as \[0,0\].
Stone \[0,0\] cannot be removed since it does not share a row/column with another stone still on the plane.

**Example 2:**

**Input:** stones = \[\[0,0\],\[0,2\],\[1,1\],\[2,0\],\[2,2\]\]
**Output:** 3
**Explanation:** One way to make 3 moves is as follows:
1. Remove stone \[2,2\] because it shares the same row as \[2,0\].
2. Remove stone \[2,0\] because it shares the same column as \[0,0\].
3. Remove stone \[0,2\] because it shares the same row as \[0,0\].
Stones \[0,0\] and \[1,1\] cannot be removed since they do not share a row/column with another stone still on the plane.

**Example 3:**

**Input:** stones = \[\[0,0\]\]
**Output:** 0
**Explanation:** \[0,0\] is the only stone on the plane, so you cannot remove it.

**Constraints:**

*   `1 <= stones.length <= 1000`
*   `0 <= xi, yi <= 104`
*   No two stones are at the same coordinate point.
Bag of Tokens

You have an initial **power** of `power`, an initial **score** of `0`, and a bag of `tokens` where `tokens[i]` is the value of the `ith` token (0-indexed).

Your goal is to maximize your total **score** by potentially playing each token in one of two ways:

*   If your current **power** is at least `tokens[i]`, you may play the `ith` token face up, losing `tokens[i]` **power** and gaining `1` **score**.
*   If your current **score** is at least `1`, you may play the `ith` token face down, gaining `tokens[i]` **power** and losing `1` **score**.

Each token may be played **at most** once and **in any order**. You do **not** have to play all the tokens.

Return _the largest possible **score** you can achieve after playing any number of tokens_.

**Example 1:**

**Input:** tokens = \[100\], power = 50
**Output:** 0
**Explanation****:** Playing the only token in the bag is impossible because you either have too little power or too little score.

**Example 2:**

**Input:** tokens = \[100,200\], power = 150
**Output:** 1
**Explanation:** Play the 0th token (100) face up, your power becomes 50 and score becomes 1.
There is no need to play the 1st token since you cannot play it face up to add to your score.

**Example 3:**

**Input:** tokens = \[100,200,300,400\], power = 200
**Output:** 2
**Explanation:** Play the tokens in this order to get a score of 2:
1. Play the 0th token (100) face up, your power becomes 100 and score becomes 1.
2. Play the 3rd token (400) face down, your power becomes 500 and score becomes 0.
3. Play the 1st token (200) face up, your power becomes 300 and score becomes 1.
4. Play the 2nd token (300) face up, your power becomes 0 and score becomes 2.

**Constraints:**

*   `0 <= tokens.length <= 1000`
*   `0 <= tokens[i], power < 104`
Largest Time for Given Digits

Given an array `arr` of 4 digits, find the latest 24-hour time that can be made using each digit **exactly once**.

24-hour times are formatted as `"HH:MM "`, where `HH` is between `00` and `23`, and `MM` is between `00` and `59`. The earliest 24-hour time is `00:00`, and the latest is `23:59`.

Return _the latest 24-hour time in `"HH:MM "` format_. If no valid time can be made, return an empty string.

**Example 1:**

**Input:** arr = \[1,2,3,4\]
**Output:**  "23:41 "
**Explanation:** The valid 24-hour times are  "12:34 ",  "12:43 ",  "13:24 ",  "13:42 ",  "14:23 ",  "14:32 ",  "21:34 ",  "21:43 ",  "23:14 ", and  "23:41 ". Of these times,  "23:41 " is the latest.

**Example 2:**

**Input:** arr = \[5,5,5,5\]
**Output:**  " "
**Explanation:** There are no valid 24-hour times as  "55:55 " is not valid.

**Constraints:**

*   `arr.length == 4`
*   `0 <= arr[i] <= 9`
Reveal Cards In Increasing Order

You are given an integer array `deck`. There is a deck of cards where every card has a unique integer. The integer on the `ith` card is `deck[i]`.

You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.

You will do the following steps repeatedly until all cards are revealed:

1.  Take the top card of the deck, reveal it, and take it out of the deck.
2.  If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.
3.  If there are still unrevealed cards, go back to step 1. Otherwise, stop.

Return _an ordering of the deck that would reveal the cards in increasing order_.

**Note** that the first entry in the answer is considered to be the top of the deck.

**Example 1:**

**Input:** deck = \[17,13,11,2,3,5,7\]
**Output:** \[2,13,3,11,5,17,7\]
**Explanation:** 
We get the deck in the order \[17,13,11,2,3,5,7\] (this order does not matter), and reorder it.
After reordering, the deck starts as \[2,13,3,11,5,17,7\], where 2 is the top of the deck.
We reveal 2, and move 13 to the bottom.  The deck is now \[3,11,5,17,7,13\].
We reveal 3, and move 11 to the bottom.  The deck is now \[5,17,7,13,11\].
We reveal 5, and move 17 to the bottom.  The deck is now \[7,13,11,17\].
We reveal 7, and move 13 to the bottom.  The deck is now \[11,17,13\].
We reveal 11, and move 17 to the bottom.  The deck is now \[13,17\].
We reveal 13, and move 17 to the bottom.  The deck is now \[17\].
We reveal 17.
Since all the cards revealed are in increasing order, the answer is correct.

**Example 2:**

**Input:** deck = \[1,1000\]
**Output:** \[1,1000\]

**Constraints:**

*   `1 <= deck.length <= 1000`
*   `1 <= deck[i] <= 106`
*   All the values of `deck` are **unique**.
Flip Equivalent Binary Trees

For a binary tree **T**, we can define a **flip operation** as follows: choose any node, and swap the left and right child subtrees.

A binary tree **X** is _flip equivalent_ to a binary tree **Y** if and only if we can make **X** equal to **Y** after some number of flip operations.

Given the roots of two binary trees `root1` and `root2`, return `true` if the two trees are flip equivalent or `false` otherwise.

**Example 1:**

**Input:** root1 = \[1,2,3,4,5,6,null,null,null,7,8\], root2 = \[1,3,2,null,6,4,5,null,null,null,null,8,7\]
**Output:** true
**Explanation:** We flipped at nodes with values 1, 3, and 5.

**Example 2:**

**Input:** root1 = \[\], root2 = \[\]
**Output:** true

**Example 3:**

**Input:** root1 = \[\], root2 = \[1\]
**Output:** false

**Constraints:**

*   The number of nodes in each tree is in the range `[0, 100]`.
*   Each tree will have **unique node values** in the range `[0, 99]`.
Largest Component Size by Common Factor

You are given an integer array of unique positive integers `nums`. Consider the following graph:

*   There are `nums.length` nodes, labeled `nums[0]` to `nums[nums.length - 1]`,
*   There is an undirected edge between `nums[i]` and `nums[j]` if `nums[i]` and `nums[j]` share a common factor greater than `1`.

Return _the size of the largest connected component in the graph_.

**Example 1:**

**Input:** nums = \[4,6,15,35\]
**Output:** 4

**Example 2:**

**Input:** nums = \[20,50,9,63\]
**Output:** 2

**Example 3:**

**Input:** nums = \[2,3,6,7,4,12,21,39\]
**Output:** 8

**Constraints:**

*   `1 <= nums.length <= 2 * 104`
*   `1 <= nums[i] <= 105`
*   All the values of `nums` are **unique**.