Leetcode Solutions

Leetcode solutions MLP Feature Image

[Solved] Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.

Question Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order. Example 1: Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4] Example 2: Input: root1 = [1,null,8], root2 = [8,1] Output: [1,1,8,8] Constraints: The number of nodes in each tree is in the range [0, 5000]. -105 <= Node.val <= […]

[Solved] Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer n, return any array containing n unique integers such that they add up to 0.

Question Given an integer n, return any array containing n unique integers such that they add up to 0. Example 1: Input: n = 5 Output: [-7,-1,1,3,4] Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4]. Example 2: Input: n = 3 Output: [-1,0,1] Example 3: Input: n = 1 Output: [0] Constraints: 1 <= n <= 1000 Python Solution

[Solved] Given an integer n, return any array containing n unique integers such that they add up to 0. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary tree, return the sum of values of its deepest leaves.

Question Given the root of a binary tree, return the sum of values of its deepest leaves. Example 1: Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8] Output: 15 Example 2: Input: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5] Output: 19 Constraints: The number of nodes in the tree is in the range [1, 104]. 1 <= Node.val <= 100 Python Solution

[Solved] Given the root of a binary tree, return the sum of values of its deepest leaves. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array.

Question Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Example 1: Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: – index 0 –> the greatest element to the right of index 0 is index 1

[Solved] Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an array nums of integers, return how many of them contain an even number of digits.

Question Given an array nums of integers, return how many of them contain an even number of digits. Example 1: Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits).  345 contains 3 digits (odd number of digits).  2 contains 1 digit (odd number of digits).  6 contains 1 digit (odd number of digits). 

[Solved] Given an array nums of integers, return how many of them contain an even number of digits. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list.

Question Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. The most significant bit is at the head of the linked list. Example 1: Input: head =

[Solved] Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.

Question Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer. Example 1: Input: arr = [1,2,2,6,6,6,6,7,10] Output: 6 Example 2: Input: arr = [1,1] Output: 1 Constraints: 1 <= arr.length <= 104 0 <= arr[i] <= 105 Python Solution

[Solved] Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer number n, return the difference between the product of its digits and the sum of its digits.

Question Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 –

[Solved] Given an integer number n, return the difference between the product of its digits and the sum of its digits. Read More »

Leetcode solutions MLP Feature Image

[Solved] On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.

Question On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points. You can move according to these rules: In 1 second, you can either: move vertically by one unit, move horizontally by one unit, or move diagonally sqrt(2) units (in other words, move one unit

[Solved] On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a 2D grid of size m x n and an integer k. You need to shift the grid k times.

Question Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n – 1] moves to grid[i + 1][0]. Element at grid[m – 1][n – 1] moves to grid[0][0]. Return the 2D grid after applying shift operation k times. Example 1: Input: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1 Output: [[9,1,2],[3,4,5],[6,7,8]] Example 2:

[Solved] Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. Read More »

Scroll to Top