Category Leetcode Solutions

[Solved] Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.

Leetcode solutions MLP Feature Image

Question Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid. Example 1: Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]] Output: 8 Explanation: There are 8 negatives number in the matrix. Example 2: Input: grid =…

[Solved] You are given an m x n binary matrix mat of 1’s (representing soldiers) and 0’s (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1’s will appear to the left of all the 0’s in each row.

Leetcode solutions MLP Feature Image

Question You are given an m x n binary matrix mat of 1‘s (representing soldiers) and 0‘s (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1‘s will appear to the left of all the 0‘s in each row. A row i is weaker than a row j if one of the…

[Solved] You are given a string s consisting only of letters ‘a’ and ‘b’. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty.

Leetcode solutions MLP Feature Image

Question You are given a string s consisting only of letters ‘a’ and ‘b’. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty. A string is a subsequence of a given string if it is generated by deleting some characters…

[Solved] You are given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).

Leetcode solutions MLP Feature Image

Question You are given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6). Example 1: Input: num = 9669 Output: 9969 Explanation: Changing the first digit results in 6669. Changing the…

[Solved] No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [A, B] where:

Leetcode solutions MLP Feature Image

Question No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [A, B] where: A and B are No-Zero integers. A + B = n The test cases are generated so that there is at least…

[Solved] Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. A grandparent of a node is the parent of its parent if it exists.

Leetcode solutions MLP Feature Image

Question Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. A grandparent of a node is the parent of its parent if it exists. Example 1: Input: root…

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

Leetcode solutions MLP Feature Image

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…

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

Leetcode solutions MLP Feature Image

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…