Leetcode Solutions

Leetcode solutions MLP Feature Image

[Solved] Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.

Question Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below. In the American keyboard: the first row consists of the characters “qwertyuiop”, the second row consists of the characters “asdfghjkl”, and the third row consists of the characters “zxcvbnm”. Example 1: […]

[Solved] Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a binary array nums, return the maximum number of consecutive 1’s in the array.

Question Given a binary array nums, return the maximum number of consecutive 1‘s in the array. Example 1: Input: nums = [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. Example 2: Input: nums = [1,0,1,1,0,1] Output: 2 Constraints: 1 <= nums.length <=

[Solved] Given a binary array nums, return the maximum number of consecutive 1’s in the array. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a string queryIP, return “IPv4” if IP is a valid IPv4 address, “IPv6” if IP is a valid IPv6 address or “Neither” if IP is not a correct IP of any type.

Question Given a string queryIP, return “IPv4” if IP is a valid IPv4 address, “IPv6” if IP is a valid IPv6 address or “Neither” if IP is not a correct IP of any type. A valid IPv4 address is an IP in the form “x1.x2.x3.x4” where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, “192.168.1.1” and “192.168.1.0” are valid IPv4 addresses while “192.168.01.1”, “192.168.1.00”, and “192.168@1.1” are invalid IPv4 addresses. A valid IPv6 address is

[Solved] Given a string queryIP, return “IPv4” if IP is a valid IPv4 address, “IPv6” if IP is a valid IPv6 address or “Neither” if IP is not a correct IP of any type. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

Question You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes”, meaning the water inside isn’t connected to the water around the island.

[Solved] You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). Read More »

Leetcode solutions MLP Feature Image

[Solved] The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, return the Hamming distance between them.

Question The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, return the Hamming distance between them. Example 1: Input: x = 1, y = 4 Output: 2 Explanation: 1 (0 0 0 1) 4 (0 1 0 0) ↑ ↑ The above arrows point to positions where the

[Solved] The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, return the Hamming distance between them. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.

Question Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Example 1: Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Example 2: Input: nums = [1,1] Output: [2] Constraints: n == nums.length 1 <= n <= 105 1 <= nums[i] <= n Follow up: Could

[Solved] Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Read More »

Leetcode solutions MLP Feature Image

[Solved] You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete. Given the integer n, return the number of complete rows of the staircase you will build.

Question You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete. Given the integer n, return the number of complete rows of the staircase you will build. Example 1: Input: n = 5 Output: 2 Explanation: Because the 3rd row is incomplete,

[Solved] You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete. Given the integer n, return the number of complete rows of the staircase you will build. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer n, return a string array answer (1-indexed) where: answer[i] == “FizzBuzz” if i is divisible by 3 and 5. answer[i] == “Fizz” if i is divisible by 3. answer[i] == “Buzz” if i is divisible by 5. answer[i] == i (as a string) if none of the above conditions are true.

Question Given an integer n, return a string array answer (1-indexed) where: answer[i] == “FizzBuzz” if i is divisible by 3 and 5. answer[i] == “Fizz” if i is divisible by 3. answer[i] == “Buzz” if i is divisible by 5. answer[i] == i (as a string) if none of the above conditions are true. Example 1: Input: n = 3 Output: [“1″,”2″,”Fizz”] Example 2: Input: n = 5 Output: [“1″,”2″,”Fizz”,”4″,”Buzz”] Example 3: Input:

[Solved] Given an integer n, return a string array answer (1-indexed) where: answer[i] == “FizzBuzz” if i is divisible by 3 and 5. answer[i] == “Fizz” if i is divisible by 3. answer[i] == “Buzz” if i is divisible by 5. answer[i] == i (as a string) if none of the above conditions are true. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

Question Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 24 Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively. Example

[Solved] Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

Question Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: Input: s = “leetcode” Output: 0 Example 2: Input: s = “loveleetcode” Output: 2 Example 3: Input: s = “aabb” Output: -1 Constraints: 1 <= s.length <= 105 s consists of only lowercase English

[Solved] Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Read More »

Scroll to Top