bowang0911/leetcode huggingface dataset:
Longest Substring with At Least K Repeating Characters

Given a string `s` and an integer `k`, return _the length of the longest substring of_ `s` _such that the frequency of each character in this substring is greater than or equal to_ `k`.

**Example 1:**

**Input:** s =  "aaabb ", k = 3
**Output:** 3
**Explanation:** The longest substring is  "aaa ", as 'a' is repeated 3 times.

**Example 2:**

**Input:** s =  "ababbc ", k = 2
**Output:** 5
**Explanation:** The longest substring is  "ababb ", as 'a' is repeated 2 times and 'b' is repeated 3 times.

**Constraints:**

*   `1 <= s.length <= 104`
*   `s` consists of only lowercase English letters.
*   `1 <= k <= 105`
Rotate Function

You are given an integer array `nums` of length `n`.

Assume `arrk` to be an array obtained by rotating `nums` by `k` positions clock-wise. We define the **rotation function** `F` on `nums` as follow:

*   `F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1].`

Return _the maximum value of_ `F(0), F(1), ..., F(n-1)`.

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

**Example 1:**

**Input:** nums = \[4,3,2,6\]
**Output:** 26
**Explanation:**
F(0) = (0 \* 4) + (1 \* 3) + (2 \* 2) + (3 \* 6) = 0 + 3 + 4 + 18 = 25
F(1) = (0 \* 6) + (1 \* 4) + (2 \* 3) + (3 \* 2) = 0 + 4 + 6 + 6 = 16
F(2) = (0 \* 2) + (1 \* 6) + (2 \* 4) + (3 \* 3) = 0 + 6 + 8 + 9 = 23
F(3) = (0 \* 3) + (1 \* 2) + (2 \* 6) + (3 \* 4) = 0 + 2 + 12 + 12 = 26
So the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.

**Example 2:**

**Input:** nums = \[100\]
**Output:** 0

**Constraints:**

*   `n == nums.length`
*   `1 <= n <= 105`
*   `-100 <= nums[i] <= 100`
Integer Replacement

Given a positive integer `n`, you can apply one of the following operations:

1.  If `n` is even, replace `n` with `n / 2`.
2.  If `n` is odd, replace `n` with either `n + 1` or `n - 1`.

Return _the minimum number of operations needed for_ `n` _to become_ `1`.

**Example 1:**

**Input:** n = 8
**Output:** 3
**Explanation:** 8 -> 4 -> 2 -> 1

**Example 2:**

**Input:** n = 7
**Output:** 4
**Explanation:** 7 -> 8 -> 4 -> 2 -> 1
or 7 -> 6 -> 3 -> 2 -> 1

**Example 3:**

**Input:** n = 4
**Output:** 2

**Constraints:**

*   `1 <= n <= 231 - 1`
Random Pick Index

Given an integer array `nums` with possible **duplicates**, randomly output the index of a given `target` number. You can assume that the given target number must exist in the array.

Implement the `Solution` class:

*   `Solution(int[] nums)` Initializes the object with the array `nums`.
*   `int pick(int target)` Picks a random index `i` from `nums` where `nums[i] == target`. If there are multiple valid i's, then each index should have an equal probability of returning.

**Example 1:**

**Input**
\[ "Solution ",  "pick ",  "pick ",  "pick "\]
\[\[\[1, 2, 3, 3, 3\]\], \[3\], \[1\], \[3\]\]
**Output**
\[null, 4, 0, 2\]

**Explanation**
Solution solution = new Solution(\[1, 2, 3, 3, 3\]);
solution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.
solution.pick(1); // It should return 0. Since in the array only nums\[0\] is equal to 1.
solution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.

**Constraints:**

*   `1 <= nums.length <= 2 * 104`
*   `-231 <= nums[i] <= 231 - 1`
*   `target` is an integer from `nums`.
*   At most `104` calls will be made to `pick`.
Evaluate Division

You are given an array of variable pairs `equations` and an array of real numbers `values`, where `equations[i] = [Ai, Bi]` and `values[i]` represent the equation `Ai / Bi = values[i]`. Each `Ai` or `Bi` is a string that represents a single variable.

You are also given some `queries`, where `queries[j] = [Cj, Dj]` represents the `jth` query where you must find the answer for `Cj / Dj = ?`.

Return _the answers to all queries_. If a single answer cannot be determined, return `-1.0`.

**Note:** The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.

**Example 1:**

**Input:** equations = \[\[ "a ", "b "\],\[ "b ", "c "\]\], values = \[2.0,3.0\], queries = \[\[ "a ", "c "\],\[ "b ", "a "\],\[ "a ", "e "\],\[ "a ", "a "\],\[ "x ", "x "\]\]
**Output:** \[6.00000,0.50000,-1.00000,1.00000,-1.00000\]
**Explanation:** 
Given: _a / b = 2.0_, _b / c = 3.0_
queries are: _a / c = ?_, _b / a = ?_, _a / e = ?_, _a / a = ?_, _x / x = ?_
return: \[6.0, 0.5, -1.0, 1.0, -1.0 \]

**Example 2:**

**Input:** equations = \[\[ "a ", "b "\],\[ "b ", "c "\],\[ "bc ", "cd "\]\], values = \[1.5,2.5,5.0\], queries = \[\[ "a ", "c "\],\[ "c ", "b "\],\[ "bc ", "cd "\],\[ "cd ", "bc "\]\]
**Output:** \[3.75000,0.40000,5.00000,0.20000\]

**Example 3:**

**Input:** equations = \[\[ "a ", "b "\]\], values = \[0.5\], queries = \[\[ "a ", "b "\],\[ "b ", "a "\],\[ "a ", "c "\],\[ "x ", "y "\]\]
**Output:** \[0.50000,2.00000,-1.00000,-1.00000\]

**Constraints:**

*   `1 <= equations.length <= 20`
*   `equations[i].length == 2`
*   `1 <= Ai.length, Bi.length <= 5`
*   `values.length == equations.length`
*   `0.0 < values[i] <= 20.0`
*   `1 <= queries.length <= 20`
*   `queries[i].length == 2`
*   `1 <= Cj.length, Dj.length <= 5`
*   `Ai, Bi, Cj, Dj` consist of lower case English letters and digits.
Nth Digit

Given an integer `n`, return the `nth` digit of the infinite integer sequence `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...]`.

**Example 1:**

**Input:** n = 3
**Output:** 3

**Example 2:**

**Input:** n = 11
**Output:** 0
**Explanation:** The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.

**Constraints:**

*   `1 <= n <= 231 - 1`
Binary Watch

A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.

*   For example, the below binary watch reads `"4:51 "`.

Given an integer `turnedOn` which represents the number of LEDs that are currently on (ignoring the PM), return _all possible times the watch could represent_. You may return the answer in **any order**.

The hour must not contain a leading zero.

*   For example, `"01:00 "` is not valid. It should be `"1:00 "`.

The minute must be consist of two digits and may contain a leading zero.

*   For example, `"10:2 "` is not valid. It should be `"10:02 "`.

**Example 1:**

**Input:** turnedOn = 1
**Output:** \["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"\]

**Example 2:**

**Input:** turnedOn = 9
**Output:** \[\]

**Constraints:**

*   `0 <= turnedOn <= 10`
Remove K Digits

Given string num representing a non-negative integer `num`, and an integer `k`, return _the smallest possible integer after removing_ `k` _digits from_ `num`.

**Example 1:**

**Input:** num =  "1432219 ", k = 3
**Output:**  "1219 "
**Explanation:** Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.

**Example 2:**

**Input:** num =  "10200 ", k = 1
**Output:**  "200 "
**Explanation:** Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.

**Example 3:**

**Input:** num =  "10 ", k = 2
**Output:**  "0 "
**Explanation:** Remove all the digits from the number and it is left with nothing which is 0.

**Constraints:**

*   `1 <= k <= num.length <= 105`
*   `num` consists of only digits.
*   `num` does not have any leading zeros except for the zero itself.
Frog Jump

A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.

Given a list of `stones`' positions (in units) in sorted **ascending order**, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be `1` unit.

If the frog's last jump was `k` units, its next jump must be either `k - 1`, `k`, or `k + 1` units. The frog can only jump in the forward direction.

**Example 1:**

**Input:** stones = \[0,1,3,5,6,8,12,17\]
**Output:** true
**Explanation:** The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.

**Example 2:**

**Input:** stones = \[0,1,2,3,4,8,9,11\]
**Output:** false
**Explanation:** There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.

**Constraints:**

*   `2 <= stones.length <= 2000`
*   `0 <= stones[i] <= 231 - 1`
*   `stones[0] == 0`
*   `stones` is sorted in a strictly increasing order.
Sum of Left Leaves

Given the `root` of a binary tree, return _the sum of all left leaves._

A **leaf** is a node with no children. A **left leaf** is a leaf that is the left child of another node.

**Example 1:**

**Input:** root = \[3,9,20,null,null,15,7\]
**Output:** 24
**Explanation:** There are two left leaves in the binary tree, with values 9 and 15 respectively.

**Example 2:**

**Input:** root = \[1\]
**Output:** 0

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 1000]`.
*   `-1000 <= Node.val <= 1000`
Convert a Number to Hexadecimal

Given an integer `num`, return _a string representing its hexadecimal representation_. For negative integers, [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) method is used.

All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.

**Note:** You are not allowed to use any built-in library method to directly solve this problem.

**Example 1:**

**Input:** num = 26
**Output:** "1a"

**Example 2:**

**Input:** num = -1
**Output:** "ffffffff"

**Constraints:**

*   `-231 <= num <= 231 - 1`
Queue Reconstruction by Height

You are given an array of people, `people`, which are the attributes of some people in a queue (not necessarily in order). Each `people[i] = [hi, ki]` represents the `ith` person of height `hi` with **exactly** `ki` other people in front who have a height greater than or equal to `hi`.

Reconstruct and return _the queue that is represented by the input array_ `people`. The returned queue should be formatted as an array `queue`, where `queue[j] = [hj, kj]` is the attributes of the `jth` person in the queue (`queue[0]` is the person at the front of the queue).

**Example 1:**

**Input:** people = \[\[7,0\],\[4,4\],\[7,1\],\[5,0\],\[6,1\],\[5,2\]\]
**Output:** \[\[5,0\],\[7,0\],\[5,2\],\[6,1\],\[4,4\],\[7,1\]\]
**Explanation:**
Person 0 has height 5 with no other people taller or the same height in front.
Person 1 has height 7 with no other people taller or the same height in front.
Person 2 has height 5 with two persons taller or the same height in front, which is person 0 and 1.
Person 3 has height 6 with one person taller or the same height in front, which is person 1.
Person 4 has height 4 with four people taller or the same height in front, which are people 0, 1, 2, and 3.
Person 5 has height 7 with one person taller or the same height in front, which is person 1.
Hence \[\[5,0\],\[7,0\],\[5,2\],\[6,1\],\[4,4\],\[7,1\]\] is the reconstructed queue.

**Example 2:**

**Input:** people = \[\[6,0\],\[5,0\],\[4,0\],\[3,2\],\[2,2\],\[1,4\]\]
**Output:** \[\[4,0\],\[5,0\],\[2,2\],\[3,2\],\[1,4\],\[6,0\]\]

**Constraints:**

*   `1 <= people.length <= 2000`
*   `0 <= hi <= 106`
*   `0 <= ki < people.length`
*   It is guaranteed that the queue can be reconstructed.
Trapping Rain Water II

Given an `m x n` integer matrix `heightMap` representing the height of each unit cell in a 2D elevation map, return _the volume of water it can trap after raining_.

**Example 1:**

**Input:** heightMap = \[\[1,4,3,1,3,2\],\[3,2,1,3,2,4\],\[2,3,3,2,3,1\]\]
**Output:** 4
**Explanation:** After the rain, water is trapped between the blocks.
We have two small ponds 1 and 3 units trapped.
The total volume of water trapped is 4.

**Example 2:**

**Input:** heightMap = \[\[3,3,3,3,3\],\[3,2,2,2,3\],\[3,2,1,2,3\],\[3,2,2,2,3\],\[3,3,3,3,3\]\]
**Output:** 10

**Constraints:**

*   `m == heightMap.length`
*   `n == heightMap[i].length`
*   `1 <= m, n <= 200`
*   `0 <= heightMap[i][j] <= 2 * 104`
Valid Word Abbreviation

A string can be **abbreviated** by replacing any number of **non-adjacent**, **non-empty** substrings with their lengths. The lengths **should not** have leading zeros.

For example, a string such as `"substitution "` could be abbreviated as (but not limited to):

*   `"s10n "` ( `"s ubstitutio n "`)
*   `"sub4u4 "` ( `"sub stit u tion "`)
*   `"12 "` ( `"substitution "`)
*   `"su3i1u2on "` ( `"su bst i t u ti on "`)
*   `"substitution "` (no substrings replaced)

The following are **not valid** abbreviations:

*   `"s55n "` ( `"s ubsti tutio n "`, the replaced substrings are adjacent)
*   `"s010n "` (has leading zeros)
*   `"s0ubstitution "` (replaces an empty substring)

Given a string `word` and an abbreviation `abbr`, return _whether the string **matches** the given abbreviation_.

A **substring** is a contiguous **non-empty** sequence of characters within a string.

**Example 1:**

**Input:** word =  "internationalization ", abbr =  "i12iz4n "
**Output:** true
**Explanation:** The word  "internationalization " can be abbreviated as  "i12iz4n " ( "i nternational iz atio n ").

**Example 2:**

**Input:** word =  "apple ", abbr =  "a2e "
**Output:** false
**Explanation:** The word  "apple " cannot be abbreviated as  "a2e ".

**Constraints:**

*   `1 <= word.length <= 20`
*   `word` consists of only lowercase English letters.
*   `1 <= abbr.length <= 10`
*   `abbr` consists of lowercase English letters and digits.
*   All the integers in `abbr` will fit in a 32-bit integer.
Longest Palindrome

Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.

Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.

**Example 1:**

**Input:** s =  "abccccdd "
**Output:** 7
**Explanation:** One longest palindrome that can be built is  "dccaccd ", whose length is 7.

**Example 2:**

**Input:** s =  "a "
**Output:** 1
**Explanation:** The longest palindrome that can be built is  "a ", whose length is 1.

**Constraints:**

*   `1 <= s.length <= 2000`
*   `s` consists of lowercase **and/or** uppercase English letters only.
Split Array Largest Sum

Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.

Return _the minimized largest sum of the split_.

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

**Example 1:**

**Input:** nums = \[7,2,5,10,8\], k = 2
**Output:** 18
**Explanation:** There are four ways to split nums into two subarrays.
The best way is to split it into \[7,2,5\] and \[10,8\], where the largest sum among the two subarrays is only 18.

**Example 2:**

**Input:** nums = \[1,2,3,4,5\], k = 2
**Output:** 9
**Explanation:** There are four ways to split nums into two subarrays.
The best way is to split it into \[1,2,3\] and \[4,5\], where the largest sum among the two subarrays is only 9.

**Constraints:**

*   `1 <= nums.length <= 1000`
*   `0 <= nums[i] <= 106`
*   `1 <= k <= min(50, nums.length)`
Minimum Unique Word Abbreviation

A string can be **abbreviated** by replacing any number of **non-adjacent** substrings with their lengths. For example, a string such as `"substitution "` could be abbreviated as (but not limited to):

*   `"s10n "` ( `"s ubstitutio n "`)
*   `"sub4u4 "` ( `"sub stit u tion "`)
*   `"12 "` ( `"substitution "`)
*   `"su3i1u2on "` ( `"su bst i t u ti on "`)
*   `"substitution "` (no substrings replaced)

Note that `"s55n "` ( `"s ubsti tutio n "`) is not a valid abbreviation of `"substitution "` because the replaced substrings are adjacent.

The **length** of an abbreviation is the number of letters that were not replaced plus the number of substrings that were replaced. For example, the abbreviation `"s10n "` has a length of `3` (`2` letters + `1` substring) and `"su3i1u2on "` has a length of `9` (`6` letters + `3` substrings).

Given a target string `target` and an array of strings `dictionary`, return _an **abbreviation** of_ `target` _with the **shortest possible length** such that it is **not an abbreviation** of **any** string in_ `dictionary`_. If there are multiple shortest abbreviations, return any of them_.

**Example 1:**

**Input:** target =  "apple ", dictionary = \[ "blade "\]
**Output:**  "a4 "
**Explanation:** The shortest abbreviation of  "apple " is  "5 ", but this is also an abbreviation of  "blade ".
The next shortest abbreviations are  "a4 " and  "4e ".  "4e " is an abbreviation of blade while  "a4 " is not.
Hence, return  "a4 ".

**Example 2:**

**Input:** target =  "apple ", dictionary = \[ "blade ", "plain ", "amber "\]
**Output:**  "1p3 "
**Explanation:**  "5 " is an abbreviation of both  "apple " but also every word in the dictionary.
 "a4 " is an abbreviation of  "apple " but also  "amber ".
 "4e " is an abbreviation of  "apple " but also  "blade ".
 "1p3 ",  "2p2 ", and  "3l1 " are the next shortest abbreviations of  "apple ".
Since none of them are abbreviations of words in the dictionary, returning any of them is correct.

**Constraints:**

*   `m == target.length`
*   `n == dictionary.length`
*   `1 <= m <= 21`
*   `0 <= n <= 1000`
*   `1 <= dictionary[i].length <= 100`
*   `log2(n) + m <= 21` if `n > 0`
*   `target` and `dictionary[i]` consist of lowercase English letters.
*   `dictionary` does not contain `target`.
Fizz Buzz

Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:

*   `answer[i] == "FizzBuzz "` if `i` is divisible by `3` and `5`.
*   `answer[i] == "Fizz "` if `i` is divisible by `3`.
*   `answer[i] == "Buzz "` if `i` is divisible by `5`.
*   `answer[i] == i` (as a string) if none of the above conditions are true.

**Example 1:**

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

**Example 2:**

**Input:** n = 5
**Output:** \["1","2","Fizz","4","Buzz"\]

**Example 3:**

**Input:** n = 15
**Output:** \["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"\]

**Constraints:**

*   `1 <= n <= 104`
Arithmetic Slices

An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.

*   For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.

Given an integer array `nums`, return _the number of arithmetic **subarrays** of_ `nums`.

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

**Example 1:**

**Input:** nums = \[1,2,3,4\]
**Output:** 3
**Explanation:** We have 3 arithmetic slices in nums: \[1, 2, 3\], \[2, 3, 4\] and \[1,2,3,4\] itself.

**Example 2:**

**Input:** nums = \[1\]
**Output:** 0

**Constraints:**

*   `1 <= nums.length <= 5000`
*   `-1000 <= nums[i] <= 1000`
Third Maximum Number

Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_.

**Example 1:**

**Input:** nums = \[3,2,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distinct maximum is 1.

**Example 2:**

**Input:** nums = \[1,2\]
**Output:** 2
**Explanation:**
The first distinct maximum is 2.
The second distinct maximum is 1.
The third distinct maximum does not exist, so the maximum (2) is returned instead.

**Example 3:**

**Input:** nums = \[2,2,3,1\]
**Output:** 1
**Explanation:**
The first distinct maximum is 3.
The second distinct maximum is 2 (both 2's are counted together since they have the same value).
The third distinct maximum is 1.

**Constraints:**

*   `1 <= nums.length <= 104`
*   `-231 <= nums[i] <= 231 - 1`

**Follow up:** Can you find an `O(n)` solution?
Add Strings

Given two non-negative integers, `num1` and `num2` represented as string, return _the sum of_ `num1` _and_ `num2` _as a string_.

You must solve the problem without using any built-in library for handling large integers (such as `BigInteger`). You must also not convert the inputs to integers directly.

**Example 1:**

**Input:** num1 =  "11 ", num2 =  "123 "
**Output:**  "134 "

**Example 2:**

**Input:** num1 =  "456 ", num2 =  "77 "
**Output:**  "533 "

**Example 3:**

**Input:** num1 =  "0 ", num2 =  "0 "
**Output:**  "0 "

**Constraints:**

*   `1 <= num1.length, num2.length <= 104`
*   `num1` and `num2` consist of only digits.
*   `num1` and `num2` don't have any leading zeros except for the zero itself.
Partition Equal Subset Sum

Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.

**Example 1:**

**Input:** nums = \[1,5,11,5\]
**Output:** true
**Explanation:** The array can be partitioned as \[1, 5, 5\] and \[11\].

**Example 2:**

**Input:** nums = \[1,2,3,5\]
**Output:** false
**Explanation:** The array cannot be partitioned into equal sum subsets.

**Constraints:**

*   `1 <= nums.length <= 200`
*   `1 <= nums[i] <= 100`
Pacific Atlantic Water Flow

There is an `m x n` rectangular island that borders both the **Pacific Ocean** and **Atlantic Ocean**. The **Pacific Ocean** touches the island's left and top edges, and the **Atlantic Ocean** touches the island's right and bottom edges.

The island is partitioned into a grid of square cells. You are given an `m x n` integer matrix `heights` where `heights[r][c]` represents the **height above sea level** of the cell at coordinate `(r, c)`.

The island receives a lot of rain, and the rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell's height is **less than or equal to** the current cell's height. Water can flow from any cell adjacent to an ocean into the ocean.

Return _a **2D list** of grid coordinates_ `result` _where_ `result[i] = [ri, ci]` _denotes that rain water can flow from cell_ `(ri, ci)` _to **both** the Pacific and Atlantic oceans_.

**Example 1:**

**Input:** heights = \[\[1,2,2,3,5\],\[3,2,3,4,4\],\[2,4,5,3,1\],\[6,7,1,4,5\],\[5,1,1,2,4\]\]
**Output:** \[\[0,4\],\[1,3\],\[1,4\],\[2,2\],\[3,0\],\[3,1\],\[4,0\]\]
**Explanation:** The following cells can flow to the Pacific and Atlantic oceans, as shown below:
\[0,4\]: \[0,4\] -> Pacific Ocean 
       \[0,4\] -> Atlantic Ocean
\[1,3\]: \[1,3\] -> \[0,3\] -> Pacific Ocean 
       \[1,3\] -> \[1,4\] -> Atlantic Ocean
\[1,4\]: \[1,4\] -> \[1,3\] -> \[0,3\] -> Pacific Ocean 
       \[1,4\] -> Atlantic Ocean
\[2,2\]: \[2,2\] -> \[1,2\] -> \[0,2\] -> Pacific Ocean 
       \[2,2\] -> \[2,3\] -> \[2,4\] -> Atlantic Ocean
\[3,0\]: \[3,0\] -> Pacific Ocean 
       \[3,0\] -> \[4,0\] -> Atlantic Ocean
\[3,1\]: \[3,1\] -> \[3,0\] -> Pacific Ocean 
       \[3,1\] -> \[4,1\] -> Atlantic Ocean
\[4,0\]: \[4,0\] -> Pacific Ocean 
       \[4,0\] -> Atlantic Ocean
Note that there are other possible paths for these cells to flow to the Pacific and Atlantic oceans.

**Example 2:**

**Input:** heights = \[\[1\]\]
**Output:** \[\[0,0\]\]
**Explanation:** The water can flow from the only cell to the Pacific and Atlantic oceans.

**Constraints:**

*   `m == heights.length`
*   `n == heights[r].length`
*   `1 <= m, n <= 200`
*   `0 <= heights[r][c] <= 105`