Given the root of a binary tree, then value
d, you need to add a row of nodes with value
vat the given depth
d. The root node is at depth 1.
The adding rule is: given a positive integer depth
d, for each NOT null tree nodes
d-1, create two tree nodes with value
N'sleft subtree root and right subtree root. And
N'soriginal left subtree should be the left subtree of the new left subtree root, its original right subtree should be the right subtree of the new…
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly
Given an integer array
nums, return the length of its longest harmonious subsequence among all its possible subsequences.
A subsequence of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.
1 <= nums.length <= 2 * 10^4
-10^9 <= nums[i] <= 10^9
For this question, I used a map just for the…
Given two strings
Bof lowercase letters, return
trueif you can swap two letters in
Aso the result is equal to
B, otherwise, return
Swapping letters is defined as taking two indices
j(0-indexed) such that
i != jand swapping the characters at
A[j]. For example, swapping at indices
0 <= A.length <= 20000
0 <= B.length <= 20000
Bconsist of lowercase letters.
For this problem, one of the…
head, the head of a linked list, determine if the linked list has a cycle in it.
There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the
posis used to denote the index of the node that tail's
nextpointer is connected to. Note that
posis not passed as a parameter.
trueif there is a cycle in the linked list. Otherwise, return
I used a set…
rootof a binary search tree and the lowest and highest boundaries as
high, trim the tree so that all its elements lies in
[low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.
Return the root of the trimmed binary search tree. Note that the root may change depending on the given bounds.
I solved this problem…
Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).
Note that in some languages such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer’s internal binary representation is the same, whether it is signed or unsigned.
In Java, the compiler represents the signed integers using 2’s complement notation. Therefore, in Example 3 above, the input represents the signed integer.
Follow up: If this…
Today, we will be looking at the following problem listed as hard with an acceptance rate of 38.6% at the time of writing.
The problem goes as follows:
rootof a binary tree, calculate the vertical order traversal of the binary tree.
For each node at position
(row, col), its left and right children will be at positions
(row + 1, col - 1)and
(row + 1, col + 1)respectively. The root of the tree is at
The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column…
Today, we will be looking at the following problem:
Given an integer
n, return the decimal value of the binary string formed by concatenating the binary representations of
nin order, modulo
10^9 + 7.
Here is my solution:
In order to figure out this problem, I had to learn about bitwise operations and how shifting bits to the left is equal to multiplying the number by
2 * (number of places shifted).
For example, if I had the number
25 which translates to
11001. A left shift would result in
110010 which is just a…
Before diving into the AWS Certified Cloud Practitioner or CCPs, let me tell you more about why “the cloud” excites me.
As you can see “the cloud” is everywhere around us. We can see that GitHub is a cloud repository for our code and services such as MongoDB Atlas or Heroku are helping you host your applications on the cloud. It’s easy to take for granted that we can very easily host those applications on storage that we do not own.
Another way we can type check is by defining the type first before referencing that type with our function.
I have a passion for coding.