Leetcode solutions MLP Feature Image

[Solved] We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list. Return the decompressed list.

Question We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list. Return the decompressed list. Example 1: […]

[Solved] We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list. Return the decompressed list. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given a string s formed by digits and ‘#’. We want to map s to English lowercase characters as follows: Characters (‘a’ to ‘i’) are represented by (‘1’ to ‘9’) respectively. Characters (‘j’ to ‘z’) are represented by (’10#’ to ’26#’) respectively.

Question You are given a string s formed by digits and ‘#’. We want to map s to English lowercase characters as follows: Characters (‘a’ to ‘i’) are represented by (‘1’ to ‘9’) respectively. Characters (‘j’ to ‘z’) are represented by (’10#’ to ’26#’) respectively. Return the string formed after mapping. The test cases are generated so that a unique mapping will always exist. Example 1: Input: s =

[Solved] You are given a string s formed by digits and ‘#’. We want to map s to English lowercase characters as follows: Characters (‘a’ to ‘i’) are represented by (‘1’ to ‘9’) respectively. Characters (‘j’ to ‘z’) are represented by (’10#’ to ’26#’) respectively. Read More »

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 »

Scroll to Top