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.
Input: text = "nlaebolko"
You are given a string
s of lowercase English letters and an integer array
shifts of the same length.
shift() of a letter, the next letter in the alphabet, (wrapping around so that
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
Return the final string after all such shifts to s are applied.
Input: s = "abc", shifts = [3,5,9]
Explanation: We start with "abc".
After shifting the first 1…
Suppose an array of length
n sorted in ascending order is rotated between
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
[0,1,2,4,5,6,7]if it was rotated
Notice that rotating an array
[a, a, a, ..., a[n-1]] 1 time results in the array
[a[n-1], a, a, a, ..., 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.
Input: nums = [3,4,5,1,2]
Explanation: The original array was…
You are given the
root of a binary tree where each node has a value
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
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.
Input: root = [1,0,1,0,1,0,1]
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.
n, return the value of Tn.
Input: n = 4
T_3 = 0 + 1 + 1 = 2
T_4 = 1 + 1 + 2 = 4
Input: n = 25
0 <= n <= 37
answer <= 2^31 - 1.
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
1. That is,
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
Input: n = 2
Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
Input: n = 3
Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
Input: n = 4
Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
0 <= n <= 30
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
'#' represents a null node.
Given a string of comma-separated values
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.