Leetcode solutions MLP Feature Image

[Solved] An array arr a mountain if the following properties hold: arr.length >= 3, There exists some i with 0 < i < arr.length - 1 such that:

Question An array arr a mountain if the following properties hold: arr.length >= 3 There exists some i with 0 < i < arr.length – 1 such that: arr[0] < arr[1] < … < arr[i – 1] < arr[i] arr[i] > arr[i + 1] > … > arr[arr.length – 1] Given a mountain array arr, return the index i such that arr[0] < arr[1] < … < […]

[Solved] An array arr a mountain if the following properties hold: arr.length >= 3, There exists some i with 0 < i < arr.length - 1 such that: Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two strings s and t, return true if they are equal when both are typed into empty text editors. ‘#’ means a backspace character.

Question Given two strings s and t, return true if they are equal when both are typed into empty text editors. ‘#’ means a backspace character. Note that after backspacing an empty text, the text will continue empty. Example 1: Input: s = “ab#c”, t = “ad#c” Output: true Explanation: Both s and t become “ac”. Example 2: Input: s = “ab##”,

[Solved] Given two strings s and t, return true if they are equal when both are typed into empty text editors. ‘#’ means a backspace character. Read More »

Leetcode solutions MLP Feature Image

[Solved] There are n rooms labeled from 0 to n – 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.

Question There are n rooms labeled from 0 to n – 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting

[Solved] There are n rooms labeled from 0 to n – 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed.

Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. For example, flipping [1,1,0] horizontally results in [0,1,1]. To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0,1,1] results in [1,0,0]. Example 1: Input: image

[Solved] Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat Latin” (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows:

Question You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat Latin” (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: If a word begins with a vowel (‘a’, ‘e’, ‘i’, ‘o’, or ‘u’),

[Solved] You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat Latin” (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.

Question Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. The distance between two indices i and j is abs(i – j), where abs is the absolute value function. Example 1: Input: s = “loveleetcode”, c = “e” Output: [3,2,1,0,1,0,0,1,2,2,1,0] Explanation: The character ‘e’ appears at indices 3, 5, 6, and 11 (0-indexed). The closest

[Solved] Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed. A subtree of a node node is node plus every node that is a descendant of node.

Question Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed. A subtree of a node node is node plus every node that is a descendant of node. Example 1: Input: root = [1,null,0,0,1] Output: [1,null,0,null,1] Explanation: Only the red nodes satisfy the property “every subtree not containing a 1”.

[Solved] Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed. A subtree of a node node is node plus every node that is a descendant of node. Read More »

Leetcode solutions MLP Feature Image

[Solved] A website domain “discuss.leetcode.com” consists of various subdomains. At the top level, we have “com”, at the next level, we have “leetcode.com” and at the lowest level, “discuss.leetcode.com”. When we visit a domain like “discuss.leetcode.com”, we will also visit the parent domains “leetcode.com” and “com” implicitly.

Question A website domain “discuss.leetcode.com” consists of various subdomains. At the top level, we have “com”, at the next level, we have “leetcode.com” and at the lowest level, “discuss.leetcode.com”. When we visit a domain like “discuss.leetcode.com”, we will also visit the parent domains “leetcode.com” and “com” implicitly. A count-paired domain is a domain that has one of the two formats “rep d1.d2.d3” or “rep d1.d2” where rep is the number of visits to the

[Solved] A website domain “discuss.leetcode.com” consists of various subdomains. At the top level, we have “com”, at the next level, we have “leetcode.com” and at the lowest level, “discuss.leetcode.com”. When we visit a domain like “discuss.leetcode.com”, we will also visit the parent domains “leetcode.com” and “com” implicitly. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of ‘a’, widths[1] is the width of ‘b’, and so on.

Question You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of ‘a’, widths[1] is the width of ‘b’, and so on. You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line

[Solved] You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of ‘a’, widths[1] is the width of ‘b’, and so on. Read More »

Leetcode solutions MLP Feature Image

[Solved] International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: ‘a’ maps to “.-“, ‘b’ maps to “-…”,

Question International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: ‘a’ maps to “.-“, ‘b’ maps to “-…”, ‘c’ maps to “-.-.”, and so on. For convenience, the full table for the 26 letters of the English alphabet is given below: [“.-“,”-…”,”-.-.”,”-..”,”.”,”..-.”,”–.”,”….”,”..”,”.—“,”-.-“,”.-..”,”–“,”-.”,”—“,”.–.”,”–.-“,”.-.”,”…”,”-“,”..-“,”…-“,”.–“,”-..-“,”-.–“,”–..”] Given an array of strings words where each word can be

[Solved] International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: ‘a’ maps to “.-“, ‘b’ maps to “-…”, Read More »

Scroll to Top