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 »

Leetcode solutions MLP Feature Image

[Solved] There is an m x n matrix that is initialized to all 0’s. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix.

Question There is an m x n matrix that is initialized to all 0‘s. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix. For each location indices[i], do both of the following: Increment all the cells on row ri. Increment all the cells on column ci. Given m, n, and indices, return the number of odd-valued cells in the matrix after applying the

[Solved] There is an m x n matrix that is initialized to all 0’s. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order.

Question Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order. While the exact formula is hidden, the function is monotonically increasing, i.e.: f(x, y) < f(x + 1, y) f(x, y) < f(x, y +

[Solved] Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order. Read More »

Leetcode solutions MLP Feature Image

[Solved] Balanced strings are those that have an equal quantity of ‘L’ and ‘R’ characters. Given a balanced string s, split it into some number of substrings such that: Each substring is balanced.

Question Balanced strings are those that have an equal quantity of ‘L’ and ‘R’ characters. Given a balanced string s, split it into some number of substrings such that: Each substring is balanced. Return the maximum number of balanced strings you can obtain. Example 1: Input: s = “RLRRLLRLRL” Output: 4 Explanation: s can be split into “RL”, “RRLL”, “RL”, “RL”, each substring contains same number

[Solved] Balanced strings are those that have an equal quantity of ‘L’ and ‘R’ characters. Given a balanced string s, split it into some number of substrings such that: Each substring is balanced. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an array of integers arr, return true if the number of occurrences of each value in the array is unique, or false otherwise.

Question Given an array of integers arr, return true if the number of occurrences of each value in the array is unique, or false otherwise. Example 1: Input: arr = [1,2,2,1,1,3] Output: true Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences. Example 2: Input: arr = [1,2]

[Solved] Given an array of integers arr, return true if the number of occurrences of each value in the array is unique, or false otherwise. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a string text, you want to use the characters of text to form as many instances of the word “balloon” as possible. You can use each character in text at most once. Return the maximum number of instances that can be formed.

Question Given a string text, you want to use the characters of text to form as many instances of the word “balloon” as possible. You can use each character in text at most once. Return the maximum number of instances that can be formed. Example 1: Input: text = “nlaebolko” Output: 1 Example 2: Input: text = “loonbalxballpoon” Output: 2 Example 3:

[Solved] Given a string text, you want to use the characters of text to form as many instances of the word “balloon” as possible. You can use each character in text at most once. Return the maximum number of instances that can be formed. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal.

Question Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Example 1: Input: root = [1,7,0,7,-8,null,null] Output: 2 Explanation: Level 1 sum = 1. Level 2 sum = 7 + 0

[Solved] Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of all good strings in words.

Question You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of all good strings in words. Example 1: Input: words = [“cat”,”bt”,”hat”,”tree”], chars = “atach” Output: 6 Explanation: The strings that can be

[Solved] You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of all good strings in words. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

Question Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, “ace” is a subsequence of “abcde”. A common subsequence of two strings is a subsequence

[Solved] Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. Read More »

Scroll to Top