Category Leetcode Solutions

[Solved] Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root. It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.

Leetcode solutions MLP Feature Image

Question Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root. It is guaranteed that there is always possible to find a binary search tree with the given requirements for the…

[Solved] Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.

Leetcode solutions MLP Feature Image

Question Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order. Example 1: Input: words = [“bella”,”label”,”roller”] Output: [“e”,”l”,”l”] Example 2: Input: words = [“cool”,”lock”,”cook”]…

[Solved] Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise.

Leetcode solutions MLP Feature Image

Question Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise. Two nodes of a binary tree are cousins if they have the…

[Solved] Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Leetcode solutions MLP Feature Image

Question Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums…

[Solved] A binary tree is uni-valued if every node in the tree has the same value. Given the root of a binary tree, return true if the given tree is uni-valued, or false otherwise.

Leetcode solutions MLP Feature Image

Question A binary tree is uni-valued if every node in the tree has the same value. Given the root of a binary tree, return true if the given tree is uni-valued, or false otherwise. Example 1: Input: root = [1,1,1,1,1,null,1] Output: true Example 2: Input: root = [2,2,2,5,2] Output:…

[Solved] You are given an integer array nums with the following properties: nums.length == 2 * n. nums contains n + 1 unique elements. Exactly one element of nums is repeated n times.

Leetcode solutions MLP Feature Image

Question You are given an integer array nums with the following properties: nums.length == 2 * n. nums contains n + 1 unique elements. Exactly one element of nums is repeated n times. Return the element that is repeated n times. Example 1: Input: nums = [1,2,3,3] Output: 3 Example 2: Input: nums…

[Solved] You are given an array of n strings strs, all of the same length. The strings can be arranged such that there is one on each line, making a grid. For example, strs = [“abc”, “bce”, “cae”] can be arranged as:

Leetcode solutions MLP Feature Image

Question You are given an array of n strings strs, all of the same length. The strings can be arranged such that there is one on each line, making a grid. For example, strs = [“abc”, “bce”, “cae”] can be arranged as: abc bce cae…

[Solved] A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where: s[i] == ‘I’ if perm[i] < perm[i + 1], and s[i] == 'D' if perm[i] > perm[i + 1].

Leetcode solutions MLP Feature Image

Question A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where: s[i] == ‘I’ if perm[i] < perm[i + 1], and s[i] == ‘D’ if perm[i] > perm[i + 1]. Given a string s, reconstruct the permutation perm and…

[Solved] Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].

Leetcode solutions MLP Feature Image

Question Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Example 1: Input: root = [10,5,15,3,7,null,18], low = 7, high = 15 Output: 32 Explanation: Nodes…