Given an `m x n`

`matrix`

, return *all elements of the* `matrix`

*in spiral order*.

**Example 1:**

**Input:** matrix = [[1,2,3],[4,5,6],[7,8,9]]

**Output:** [1,2,3,6,9,8,7,4,5]

**Example 2:**

Given a string `text`

, you want to use the characters of `text`

to form as many instances of the word **"balloon"** as possible.

You can use each character in `text`

**at most once**. Return the maximum number of instances that can be formed.

**Example 1:**

**Input:** text = "nlaebolko"

**Output:** 1

**Example 2:**

Given the `head`

of a sorted linked list, *delete all duplicates such that each element appears only once*. Return *the linked list **sorted** as well*.

**Example 1:**

**Input:** head = [1,1,2]

**Output:** [1,2]

**Example 2:**

You are given a string `s`

of lowercase English letters and an integer array `shifts`

of the same length.

Call the `shift()`

of a letter, the next letter in the alphabet, (wrapping around so that `'z'`

becomes `'a'`

).

- For example,
`shift('a') = 'b'`

,`shift('t') = 'u'`

, and`shift('z') = 'a'`

.

Now for each `shifts[i] = x`

, we want to shift the first `i + 1`

letters of `s`

, `x`

times.

Return *the final string after all such shifts to s are applied*.

**Example 1:**

**Input:** s = "abc", shifts = [3,5,9]

**Output:** "rpl"

**Explanation:** We start with "abc".

After shifting the first 1…

Given the `head`

of a singly linked list, reverse the list, and return *the reversed list*.

**Example 1:**

**Input:** head = [1,2,3,4,5]

**Output:** [5,4,3,2,1]

**Example 2:**

Suppose an array of length `n`

sorted in ascending order is **rotated** between `1`

and `n`

times. For example, the array `nums = [0,1,2,4,5,6,7]`

might become:

`[4,5,6,7,0,1,2]`

if it was rotated`4`

times.`[0,1,2,4,5,6,7]`

if it was rotated`7`

times.

Notice that **rotating** an array `[a[0], a[1], a[2], ..., a[n-1]]`

1 time results in the array `[a[n-1], a[0], a[1], a[2], ..., a[n-2]]`

.

Given the sorted rotated array `nums`

of **unique** elements, return *the minimum element of this array*.

You must write an algorithm that runs in `O(log n) time.`

**Example 1:**

**Input:** nums = [3,4,5,1,2]

**Output:** 1

**Explanation:** The original array was…

You are given the `root`

of a binary tree where each node has a value `0`

or `1`

. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is `0 -> 1 -> 1 -> 0 -> 1`

, then this could represent `01101`

in binary, which is `13`

.

For all leaves in the tree, consider the numbers represented by the path from the root to that leaf.

Return *the sum of these numbers*. The answer is **guaranteed** to fit in a **32-bits** integer.

**Example 1:**

**Input:** root = [1,0,1,0,1,0,1]

**Output:** 22

**Explanation: **(100) +…

The Tribonacci sequence Tn is defined as follows:

T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.

Given `n`

, return the value of Tn.

**Example 1:**

**Input:** n = 4

**Output:** 4

**Explanation:**

T_3 = 0 + 1 + 1 = 2

T_4 = 1 + 1 + 2 = 4

**Example 2:**

**Input:** n = 25

**Output:** 1389537

**Constraints:**

`0 <= n <= 37`

- The answer is guaranteed to fit within a 32-bit integer, ie.
`answer <= 2^31 - 1`

.

Solution:

The **Fibonacci numbers**, commonly denoted `F(n)`

form a sequence, called the **Fibonacci sequence**, such that each number is the sum of the two preceding ones, starting from `0`

and `1`

. That is,

`F(0) = 0, F(1) = 1`

F(n) = F(n - 1) + F(n - 2), for n > 1.

Given `n`

, calculate `F(n)`

.

**Example 1:**

**Input:** n = 2

**Output:** 1

**Explanation:** F(2) = F(1) + F(0) = 1 + 0 = 1.

**Example 2:**

**Input:** n = 3

**Output:** 2

**Explanation:** F(3) = F(2) + F(1) = 1 + 1 = 2.

**Example 3:**

**Input:** n = 4

**Output:** 3

**Explanation:** F(4) = F(3) + F(2) = 2 + 1 = 3.

**Constraints:**

`0 <= n <= 30`

Solution:

Time Complexity: O(n)

One way to serialize a binary tree is to use **preorder traversal**. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as `'#'`

.

For example, the above binary tree can be serialized to the string `"9,3,4,#,#,1,#,#,2,#,6,#,#"`

, where `'#'`

represents a null node.

Given a string of comma-separated values `preorder`

, return `true`

if it is a correct preorder traversal serialization of a binary tree.

It is **guaranteed** that each comma-separated value in the string must be either an integer or a character `'#'`

representing null pointer.

…