Leetcode solutions MLP Feature Image

[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].

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 return it. If there are multiple valid permutations perm, return any of them. Example 1: Input: […]

[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]. Read More »

Leetcode solutions MLP Feature Image

[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].

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 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15

[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]. Read More »

Leetcode solutions MLP Feature Image

[Solved] Every valid email consists of a local name and a domain name, separated by the ‘@’ sign. Besides lowercase letters, the email may contain one or more ‘.’ or ‘+’. For example, in “alice@leetcode.com”, “alice” is the local name, and “leetcode.com” is the domain name.

Question Every valid email consists of a local name and a domain name, separated by the ‘@’ sign. Besides lowercase letters, the email may contain one or more ‘.’ or ‘+’. For example, in “alice@leetcode.com”, “alice” is the local name, and “leetcode.com” is the domain name. If you add periods ‘.’ between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in

[Solved] Every valid email consists of a local name and a domain name, separated by the ‘@’ sign. Besides lowercase letters, the email may contain one or more ‘.’ or ‘+’. For example, in “alice@leetcode.com”, “alice” is the local name, and “leetcode.com” is the domain name. Read More »

Leetcode solutions MLP Feature Image

[Solved] Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.

Question Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times. You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed. Example 1: Input:

[Solved] Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition.

Question Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. Example 1: Input: nums = [3,1,2,4] Output: [2,4,3,1] Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Example 2: Input: nums = [0] Output: [0] Constraints:

[Solved] Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.

Question Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child. Example 1: Input: root = [5,3,6,2,4,null,8,1,null,null,null,7,9] Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9] Example 2: Input: root = [5,1,7] Output: [1,null,5,null,7] Constraints: The

[Solved] Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child. Read More »

Leetcode solutions MLP Feature Image

[Solved] A sentence is a string of single-space separated words where each word consists only of lowercase letters.

Question A sentence is a string of single-space separated words where each word consists only of lowercase letters. A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence. Given two sentences s1 and s2, return a list of all the uncommon words. You may return the answer in any order. Example 1: Input: s1 = “this

[Solved] A sentence is a string of single-space separated words where each word consists only of lowercase letters. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.

Question Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. Example 1: Input: head = [1,2,3,4,5] Output: [3,4,5] Explanation: The middle node of the list is node 3. Example 2: Input: head = [1,2,3,4,5,6] Output: [4,5,6] Explanation: Since the list has two

[Solved] Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. Read More »

Leetcode solutions MLP Feature Image

[Solved] Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence.

Question Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8). Two binary trees are considered leaf-similar if their leaf value sequence is the same. Return true if and only if the two

[Solved] Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix’s row and column indices.

Question Given a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix’s row and column indices. Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,4,7],[2,5,8],[3,6,9]] Example 2: Input: matrix = [[1,2,3],[4,5,6]] Output: [[1,4],[2,5],[3,6]] Constraints: m == matrix.length n == matrix[i].length 1 <= m, n <= 1000 1

[Solved] Given a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix’s row and column indices. Read More »

Scroll to Top