bowang0911/leetcode huggingface dataset:
Implement Stack using Queues

Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (`push`, `top`, `pop`, and `empty`).

Implement the `MyStack` class:

*   `void push(int x)` Pushes element x to the top of the stack.
*   `int pop()` Removes the element on the top of the stack and returns it.
*   `int top()` Returns the element on the top of the stack.
*   `boolean empty()` Returns `true` if the stack is empty, `false` otherwise.

**Notes:**

*   You must use **only** standard operations of a queue, which means that only `push to back`, `peek/pop from front`, `size` and `is empty` operations are valid.
*   Depending on your language, the queue may not be supported natively. You may simulate a queue using a list or deque (double-ended queue) as long as you use only a queue's standard operations.

**Example 1:**

**Input**
\[ "MyStack ",  "push ",  "push ",  "top ",  "pop ",  "empty "\]
\[\[\], \[1\], \[2\], \[\], \[\], \[\]\]
**Output**
\[null, null, null, 2, 2, false\]

**Explanation**
MyStack myStack = new MyStack();
myStack.push(1);
myStack.push(2);
myStack.top(); // return 2
myStack.pop(); // return 2
myStack.empty(); // return False

**Constraints:**

*   `1 <= x <= 9`
*   At most `100` calls will be made to `push`, `pop`, `top`, and `empty`.
*   All the calls to `pop` and `top` are valid.

**Follow-up:** Can you implement the stack using only one queue?
Invert Binary Tree

Given the `root` of a binary tree, invert the tree, and return _its root_.

**Example 1:**

**Input:** root = \[4,2,7,1,3,6,9\]
**Output:** \[4,7,2,9,6,3,1\]

**Example 2:**

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

**Example 3:**

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

**Constraints:**

*   The number of nodes in the tree is in the range `[0, 100]`.
*   `-100 <= Node.val <= 100`
Basic Calculator II

Given a string `s` which represents an expression, _evaluate this expression and return its value_.

The integer division should truncate toward zero.

You may assume that the given expression is always valid. All intermediate results will be in the range of `[-231, 231 - 1]`.

**Note:** You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as `eval()`.

**Example 1:**

**Input:** s = "3+2\*2"
**Output:** 7

**Example 2:**

**Input:** s = " 3/2 "
**Output:** 1

**Example 3:**

**Input:** s = " 3+5 / 2 "
**Output:** 5

**Constraints:**

*   `1 <= s.length <= 3 * 105`
*   `s` consists of integers and operators `('+', '-', '*', '/')` separated by some number of spaces.
*   `s` represents **a valid expression**.
*   All the integers in the expression are non-negative integers in the range `[0, 231 - 1]`.
*   The answer is **guaranteed** to fit in a **32-bit integer**.
Summary Ranges

You are given a **sorted unique** integer array `nums`.

A **range** `[a,b]` is the set of all integers from `a` to `b` (inclusive).

Return _the **smallest sorted** list of ranges that **cover all the numbers in the array exactly**_. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`.

Each range `[a,b]` in the list should be output as:

*   `"a->b "` if `a != b`
*   `"a "` if `a == b`

**Example 1:**

**Input:** nums = \[0,1,2,4,5,7\]
**Output:** \[ "0->2 ", "4->5 ", "7 "\]
**Explanation:** The ranges are:
\[0,2\] -->  "0->2 "
\[4,5\] -->  "4->5 "
\[7,7\] -->  "7 "

**Example 2:**

**Input:** nums = \[0,2,3,4,6,8,9\]
**Output:** \[ "0 ", "2->4 ", "6 ", "8->9 "\]
**Explanation:** The ranges are:
\[0,0\] -->  "0 "
\[2,4\] -->  "2->4 "
\[6,6\] -->  "6 "
\[8,9\] -->  "8->9 "

**Constraints:**

*   `0 <= nums.length <= 20`
*   `-231 <= nums[i] <= 231 - 1`
*   All the values of `nums` are **unique**.
*   `nums` is sorted in ascending order.
Majority Element II

Given an integer array of size `n`, find all elements that appear more than `⌊ n/3 ⌋` times.

**Example 1:**

**Input:** nums = \[3,2,3\]
**Output:** \[3\]

**Example 2:**

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

**Example 3:**

**Input:** nums = \[1,2\]
**Output:** \[1,2\]

**Constraints:**

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

**Follow up:** Could you solve the problem in linear time and in `O(1)` space?
Kth Smallest Element in a BST

Given the `root` of a binary search tree, and an integer `k`, return _the_ `kth` _smallest value (**1-indexed**) of all the values of the nodes in the tree_.

**Example 1:**

**Input:** root = \[3,1,4,null,2\], k = 1
**Output:** 1

**Example 2:**

**Input:** root = \[5,3,6,2,4,null,null,1\], k = 3
**Output:** 3

**Constraints:**

*   The number of nodes in the tree is `n`.
*   `1 <= k <= n <= 104`
*   `0 <= Node.val <= 104`

**Follow up:** If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?
Power of Two

Given an integer `n`, return _`true` if it is a power of two. Otherwise, return `false`_.

An integer `n` is a power of two, if there exists an integer `x` such that `n == 2x`.

**Example 1:**

**Input:** n = 1
**Output:** true
**Explanation:** 20 = 1

**Example 2:**

**Input:** n = 16
**Output:** true
**Explanation:** 24 = 16

**Example 3:**

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

**Constraints:**

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

**Follow up:** Could you solve it without loops/recursion?
Implement Queue using Stacks

Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (`push`, `peek`, `pop`, and `empty`).

Implement the `MyQueue` class:

*   `void push(int x)` Pushes element x to the back of the queue.
*   `int pop()` Removes the element from the front of the queue and returns it.
*   `int peek()` Returns the element at the front of the queue.
*   `boolean empty()` Returns `true` if the queue is empty, `false` otherwise.

**Notes:**

*   You must use **only** standard operations of a stack, which means only `push to top`, `peek/pop from top`, `size`, and `is empty` operations are valid.
*   Depending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.

**Example 1:**

**Input**
\[ "MyQueue ",  "push ",  "push ",  "peek ",  "pop ",  "empty "\]
\[\[\], \[1\], \[2\], \[\], \[\], \[\]\]
**Output**
\[null, null, null, 1, 1, false\]

**Explanation**
MyQueue myQueue = new MyQueue();
myQueue.push(1); // queue is: \[1\]
myQueue.push(2); // queue is: \[1, 2\] (leftmost is front of the queue)
myQueue.peek(); // return 1
myQueue.pop(); // return 1, queue is \[2\]
myQueue.empty(); // return false

**Constraints:**

*   `1 <= x <= 9`
*   At most `100` calls will be made to `push`, `pop`, `peek`, and `empty`.
*   All the calls to `pop` and `peek` are valid.

**Follow-up:** Can you implement the queue such that each operation is **[amortized](https://en.wikipedia.org/wiki/Amortized_analysis)** `O(1)` time complexity? In other words, performing `n` operations will take overall `O(n)` time even if one of those operations may take longer.
Number of Digit One

Given an integer `n`, count _the total number of digit_ `1` _appearing in all non-negative integers less than or equal to_ `n`.

**Example 1:**

**Input:** n = 13
**Output:** 6

**Example 2:**

**Input:** n = 0
**Output:** 0

**Constraints:**

*   `0 <= n <= 109`
Palindrome Linked List

Given the `head` of a singly linked list, return `true` _if it is a_ _palindrome_ _or_ `false` _otherwise_.

**Example 1:**

**Input:** head = \[1,2,2,1\]
**Output:** true

**Example 2:**

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

**Constraints:**

*   The number of nodes in the list is in the range `[1, 105]`.
*   `0 <= Node.val <= 9`

**Follow up:** Could you do it in `O(n)` time and `O(1)` space?
Lowest Common Ancestor of a Binary Search Tree

Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.

According to the [definition of LCA on Wikipedia](https://en.wikipedia.org/wiki/Lowest_common_ancestor): "The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in `T` that has both `p` and `q` as descendants (where we allow **a node to be a descendant of itself**)."

**Example 1:**

**Input:** root = \[6,2,8,0,4,7,9,null,null,3,5\], p = 2, q = 8
**Output:** 6
**Explanation:** The LCA of nodes 2 and 8 is 6.

**Example 2:**

**Input:** root = \[6,2,8,0,4,7,9,null,null,3,5\], p = 2, q = 4
**Output:** 2
**Explanation:** The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.

**Example 3:**

**Input:** root = \[2,1\], p = 2, q = 1
**Output:** 2

**Constraints:**

*   The number of nodes in the tree is in the range `[2, 105]`.
*   `-109 <= Node.val <= 109`
*   All `Node.val` are **unique**.
*   `p != q`
*   `p` and `q` will exist in the BST.
Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

According to the [definition of LCA on Wikipedia](https://en.wikipedia.org/wiki/Lowest_common_ancestor): "The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in `T` that has both `p` and `q` as descendants (where we allow **a node to be a descendant of itself**)."

**Example 1:**

**Input:** root = \[3,5,1,6,2,0,8,null,null,7,4\], p = 5, q = 1
**Output:** 3
**Explanation:** The LCA of nodes 5 and 1 is 3.

**Example 2:**

**Input:** root = \[3,5,1,6,2,0,8,null,null,7,4\], p = 5, q = 4
**Output:** 5
**Explanation:** The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.

**Example 3:**

**Input:** root = \[1,2\], p = 1, q = 2
**Output:** 1

**Constraints:**

*   The number of nodes in the tree is in the range `[2, 105]`.
*   `-109 <= Node.val <= 109`
*   All `Node.val` are **unique**.
*   `p != q`
*   `p` and `q` will exist in the tree.
Delete Node in a Linked List

There is a singly-linked list `head` and we want to delete a node `node` in it.

You are given the node to be deleted `node`. You will **not be given access** to the first node of `head`.

All the values of the linked list are **unique**, and it is guaranteed that the given node `node` is not the last node in the linked list.

Delete the given node. Note that by deleting the node, we do not mean removing it from memory. We mean:

*   The value of the given node should not exist in the linked list.
*   The number of nodes in the linked list should decrease by one.
*   All the values before `node` should be in the same order.
*   All the values after `node` should be in the same order.

**Custom testing:**

*   For the input, you should provide the entire linked list `head` and the node to be given `node`. `node` should not be the last node of the list and should be an actual node in the list.
*   We will build the linked list and pass the node to your function.
*   The output will be the entire list after calling your function.

**Example 1:**

**Input:** head = \[4,5,1,9\], node = 5
**Output:** \[4,1,9\]
**Explanation:** You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.

**Example 2:**

**Input:** head = \[4,5,1,9\], node = 1
**Output:** \[4,5,9\]
**Explanation:** You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.

**Constraints:**

*   The number of the nodes in the given list is in the range `[2, 1000]`.
*   `-1000 <= Node.val <= 1000`
*   The value of each node in the list is **unique**.
*   The `node` to be deleted is **in the list** and is **not a tail** node.
Product of Array Except Self

Given an integer array `nums`, return _an array_ `answer` _such that_ `answer[i]` _is equal to the product of all the elements of_ `nums` _except_ `nums[i]`.

The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer.

You must write an algorithm that runs in `O(n)` time and without using the division operation.

**Example 1:**

**Input:** nums = \[1,2,3,4\]
**Output:** \[24,12,8,6\]

**Example 2:**

**Input:** nums = \[-1,1,0,-3,3\]
**Output:** \[0,0,9,0,0\]

**Constraints:**

*   `2 <= nums.length <= 105`
*   `-30 <= nums[i] <= 30`
*   The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer.

**Follow up:** Can you solve the problem in `O(1)` extra space complexity? (The output array **does not** count as extra space for space complexity analysis.)
Sliding Window Maximum

You are given an array of integers `nums`, there is a sliding window of size `k` which is moving from the very left of the array to the very right. You can only see the `k` numbers in the window. Each time the sliding window moves right by one position.

Return _the max sliding window_.

**Example 1:**

**Input:** nums = \[1,3,-1,-3,5,3,6,7\], k = 3
**Output:** \[3,3,5,5,6,7\]
**Explanation:** 
Window position                Max
---------------               -----
\[1  3  -1\] -3  5  3  6  7       **3**
 1 \[3  -1  -3\] 5  3  6  7       **3**
 1  3 \[-1  -3  5\] 3  6  7      ** 5**
 1  3  -1 \[-3  5  3\] 6  7       **5**
 1  3  -1  -3 \[5  3  6\] 7       **6**
 1  3  -1  -3  5 \[3  6  7\]      **7**

**Example 2:**

**Input:** nums = \[1\], k = 1
**Output:** \[1\]

**Constraints:**

*   `1 <= nums.length <= 105`
*   `-104 <= nums[i] <= 104`
*   `1 <= k <= nums.length`
Search a 2D Matrix II

Write an efficient algorithm that searches for a value `target` in an `m x n` integer matrix `matrix`. This matrix has the following properties:

*   Integers in each row are sorted in ascending from left to right.
*   Integers in each column are sorted in ascending from top to bottom.

**Example 1:**

**Input:** matrix = \[\[1,4,7,11,15\],\[2,5,8,12,19\],\[3,6,9,16,22\],\[10,13,14,17,24\],\[18,21,23,26,30\]\], target = 5
**Output:** true

**Example 2:**

**Input:** matrix = \[\[1,4,7,11,15\],\[2,5,8,12,19\],\[3,6,9,16,22\],\[10,13,14,17,24\],\[18,21,23,26,30\]\], target = 20
**Output:** false

**Constraints:**

*   `m == matrix.length`
*   `n == matrix[i].length`
*   `1 <= n, m <= 300`
*   `-109 <= matrix[i][j] <= 109`
*   All the integers in each row are **sorted** in ascending order.
*   All the integers in each column are **sorted** in ascending order.
*   `-109 <= target <= 109`
Different Ways to Add Parentheses

Given a string `expression` of numbers and operators, return _all possible results from computing all the different possible ways to group numbers and operators_. You may return the answer in **any order**.

The test cases are generated such that the output values fit in a 32-bit integer and the number of different results does not exceed `104`.

**Example 1:**

**Input:** expression =  "2-1-1 "
**Output:** \[0,2\]
**Explanation:**
((2-1)-1) = 0 
(2-(1-1)) = 2

**Example 2:**

**Input:** expression =  "2\*3-4\*5 "
**Output:** \[-34,-14,-10,-10,10\]
**Explanation:**
(2\*(3-(4\*5))) = -34 
((2\*3)-(4\*5)) = -14 
((2\*(3-4))\*5) = -10 
(2\*((3-4)\*5)) = -10 
(((2\*3)-4)\*5) = 10

**Constraints:**

*   `1 <= expression.length <= 20`
*   `expression` consists of digits and the operator `'+'`, `'-'`, and `'*'`.
*   All the integer values in the input expression are in the range `[0, 99]`.
Valid Anagram

Given two strings `s` and `t`, return `true` _if_ `t` _is an anagram of_ `s`_, and_ `false` _otherwise_.

An **Anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

**Example 1:**

**Input:** s = "anagram", t = "nagaram"
**Output:** true

**Example 2:**

**Input:** s = "rat", t = "car"
**Output:** false

**Constraints:**

*   `1 <= s.length, t.length <= 5 * 104`
*   `s` and `t` consist of lowercase English letters.

**Follow up:** What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
Shortest Word Distance

Given an array of strings `wordsDict` and two different strings that already exist in the array `word1` and `word2`, return _the shortest distance between these two words in the list_.

**Example 1:**

**Input:** wordsDict = \[ "practice ",  "makes ",  "perfect ",  "coding ",  "makes "\], word1 =  "coding ", word2 =  "practice "
**Output:** 3

**Example 2:**

**Input:** wordsDict = \[ "practice ",  "makes ",  "perfect ",  "coding ",  "makes "\], word1 =  "makes ", word2 =  "coding "
**Output:** 1

**Constraints:**

*   `2 <= wordsDict.length <= 3 * 104`
*   `1 <= wordsDict[i].length <= 10`
*   `wordsDict[i]` consists of lowercase English letters.
*   `word1` and `word2` are in `wordsDict`.
*   `word1 != word2`
Shortest Word Distance II

Design a data structure that will be initialized with a string array, and then it should answer queries of the shortest distance between two different strings from the array.

Implement the `WordDistance` class:

*   `WordDistance(String[] wordsDict)` initializes the object with the strings array `wordsDict`.
*   `int shortest(String word1, String word2)` returns the shortest distance between `word1` and `word2` in the array `wordsDict`.

**Example 1:**

**Input**
\[ "WordDistance ",  "shortest ",  "shortest "\]
\[\[\[ "practice ",  "makes ",  "perfect ",  "coding ",  "makes "\]\], \[ "coding ",  "practice "\], \[ "makes ",  "coding "\]\]
**Output**
\[null, 3, 1\]

**Explanation**
WordDistance wordDistance = new WordDistance(\[ "practice ",  "makes ",  "perfect ",  "coding ",  "makes "\]);
wordDistance.shortest( "coding ",  "practice "); // return 3
wordDistance.shortest( "makes ",  "coding ");    // return 1

**Constraints:**

*   `1 <= wordsDict.length <= 3 * 104`
*   `1 <= wordsDict[i].length <= 10`
*   `wordsDict[i]` consists of lowercase English letters.
*   `word1` and `word2` are in `wordsDict`.
*   `word1 != word2`
*   At most `5000` calls will be made to `shortest`.
Shortest Word Distance III

Given an array of strings `wordsDict` and two strings that already exist in the array `word1` and `word2`, return _the shortest distance between the occurrence of these two words in the list_.

**Note** that `word1` and `word2` may be the same. It is guaranteed that they represent **two individual words** in the list.

**Example 1:**

**Input:** wordsDict = \["practice", "makes", "perfect", "coding", "makes"\], word1 = "makes", word2 = "coding"
**Output:** 1

**Example 2:**

**Input:** wordsDict = \["practice", "makes", "perfect", "coding", "makes"\], word1 = "makes", word2 = "makes"
**Output:** 3

**Constraints:**

*   `1 <= wordsDict.length <= 105`
*   `1 <= wordsDict[i].length <= 10`
*   `wordsDict[i]` consists of lowercase English letters.
*   `word1` and `word2` are in `wordsDict`.
Strobogrammatic Number

Given a string `num` which represents an integer, return `true` _if_ `num` _is a **strobogrammatic number**_.

A **strobogrammatic number** is a number that looks the same when rotated `180` degrees (looked at upside down).

**Example 1:**

**Input:** num =  "69 "
**Output:** true

**Example 2:**

**Input:** num =  "88 "
**Output:** true

**Example 3:**

**Input:** num =  "962 "
**Output:** false

**Constraints:**

*   `1 <= num.length <= 50`
*   `num` consists of only digits.
*   `num` does not contain any leading zeros except for zero itself.
Strobogrammatic Number II

Given an integer `n`, return all the **strobogrammatic numbers** that are of length `n`. You may return the answer in **any order**.

A **strobogrammatic number** is a number that looks the same when rotated `180` degrees (looked at upside down).

**Example 1:**

**Input:** n = 2
**Output:** \["11","69","88","96"\]

**Example 2:**

**Input:** n = 1
**Output:** \["0","1","8"\]

**Constraints:**

*   `1 <= n <= 14`
Strobogrammatic Number III

Given two strings low and high that represent two integers `low` and `high` where `low <= high`, return _the number of **strobogrammatic numbers** in the range_ `[low, high]`.

A **strobogrammatic number** is a number that looks the same when rotated `180` degrees (looked at upside down).

**Example 1:**

**Input:** low = "50", high = "100"
**Output:** 3

**Example 2:**

**Input:** low = "0", high = "0"
**Output:** 1

**Constraints:**

*   `1 <= low.length, high.length <= 15`
*   `low` and `high` consist of only digits.
*   `low <= high`
*   `low` and `high` do not contain any leading zeros except for zero itself.
Group Shifted Strings

We can shift a string by shifting each of its letters to its successive letter.

*   For example, `"abc "` can be shifted to be `"bcd "`.

We can keep shifting the string to form a sequence.

*   For example, we can keep shifting `"abc "` to form the sequence: `"abc " -> "bcd " -> ... -> "xyz "`.

Given an array of strings `strings`, group all `strings[i]` that belong to the same shifting sequence. You may return the answer in **any order**.

**Example 1:**

**Input:** strings = \["abc","bcd","acef","xyz","az","ba","a","z"\]
**Output:** \[\["acef"\],\["a","z"\],\["abc","bcd","xyz"\],\["az","ba"\]\]

**Example 2:**

**Input:** strings = \["a"\]
**Output:** \[\["a"\]\]

**Constraints:**

*   `1 <= strings.length <= 200`
*   `1 <= strings[i].length <= 50`
*   `strings[i]` consists of lowercase English letters.
Count Univalue Subtrees

Given the `root` of a binary tree, return _the number of **uni-value**_ _subtrees_.

A **uni-value subtree** means all nodes of the subtree have the same value.

**Example 1:**

**Input:** root = \[5,1,5,5,5,null,5\]
**Output:** 4

**Example 2:**

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

**Example 3:**

**Input:** root = \[5,5,5,5,5,null,5\]
**Output:** 6

**Constraints:**

*   The number of the node in the tree will be in the range `[0, 1000]`.
*   `-1000 <= Node.val <= 1000`
Flatten 2D Vector

Design an iterator to flatten a 2D vector. It should support the `next` and `hasNext` operations.

Implement the `Vector2D` class:

*   `Vector2D(int[][] vec)` initializes the object with the 2D vector `vec`.
*   `next()` returns the next element from the 2D vector and moves the pointer one step forward. You may assume that all the calls to `next` are valid.
*   `hasNext()` returns `true` if there are still some elements in the vector, and `false` otherwise.

**Example 1:**

**Input**
\[ "Vector2D ",  "next ",  "next ",  "next ",  "hasNext ",  "hasNext ",  "next ",  "hasNext "\]
\[\[\[\[1, 2\], \[3\], \[4\]\]\], \[\], \[\], \[\], \[\], \[\], \[\], \[\]\]
**Output**
\[null, 1, 2, 3, true, true, 4, false\]

**Explanation**
Vector2D vector2D = new Vector2D(\[\[1, 2\], \[3\], \[4\]\]);
vector2D.next();    // return 1
vector2D.next();    // return 2
vector2D.next();    // return 3
vector2D.hasNext(); // return True
vector2D.hasNext(); // return True
vector2D.next();    // return 4
vector2D.hasNext(); // return False

**Constraints:**

*   `0 <= vec.length <= 200`
*   `0 <= vec[i].length <= 500`
*   `-500 <= vec[i][j] <= 500`
*   At most `105` calls will be made to `next` and `hasNext`.

**Follow up:** As an added challenge, try to code it using only [iterators in C++](http://www.cplusplus.com/reference/iterator/iterator/) or [iterators in Java](http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html).
Meeting Rooms

Given an array of meeting time `intervals` where `intervals[i] = [starti, endi]`, determine if a person could attend all meetings.

**Example 1:**

**Input:** intervals = \[\[0,30\],\[5,10\],\[15,20\]\]
**Output:** false

**Example 2:**

**Input:** intervals = \[\[7,10\],\[2,4\]\]
**Output:** true

**Constraints:**

*   `0 <= intervals.length <= 104`
*   `intervals[i].length == 2`
*   `0 <= starti < endi <= 106`
Meeting Rooms II

Given an array of meeting time intervals `intervals` where `intervals[i] = [starti, endi]`, return _the minimum number of conference rooms required_.

**Example 1:**

**Input:** intervals = \[\[0,30\],\[5,10\],\[15,20\]\]
**Output:** 2

**Example 2:**

**Input:** intervals = \[\[7,10\],\[2,4\]\]
**Output:** 1

**Constraints:**

*   `1 <= intervals.length <= 104`
*   `0 <= starti < endi <= 106`