Leetcode Solutions

Leetcode solutions MLP Feature Image

[Solved] Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., “ace” is a subsequence of “abcde” while “aec” is not).

Question Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., “ace” is a subsequence of “abcde” while “aec” is not). Example 1: Input: s = “abc”, t = “ahbgdc” Output: true […]

[Solved] Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., “ace” is a subsequence of “abcde” while “aec” is not). Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t.

Question You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t. Example 1: Input: s = “abcd”, t = “abcde” Output: “e” Explanation: ‘e’ is the letter that was added. Example 2: Input: s = “”, t =

[Solved] You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.

Question Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ransomNote. Example 1: Input: ransomNote = “a”, magazine = “b” Output: false Example 2: Input: ransomNote = “aa”, magazine = “ab” Output: false Example 3: Input: ransomNote = “aa”, magazine = “aab” Output: true Constraints: 1

[Solved] Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Read More »

Leetcode solutions MLP Feature Image

[Solved] We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined API int guess(int num), which returns three possible results:

Question We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined API int guess(int num), which returns

[Solved] We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined API int guess(int num), which returns three possible results: Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a positive integer num, write a function which returns True if num is a perfect square else False.

Question Given a positive integer num, write a function which returns True if num is a perfect square else False. Follow up: Do not use any built-in library function such as sqrt. Example 1: Input: num = 16 Output: true Example 2: Input: num = 14 Output: false Constraints: 1 <= num <= 2^31 – 1 Python Solution

[Solved] Given a positive integer num, write a function which returns True if num is a perfect square else False. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.

Question Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output:

[Solved] Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.

Question Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2] Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [9,4] Explanation: [4,9] is also accepted. Constraints: 1 <= nums1.length,

[Solved] Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a string s, reverse only all the vowels in the string and return it.

Question Given a string s, reverse only all the vowels in the string and return it. The vowels are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’, and they can appear in both cases. Example 1: Input: s = “hello” Output: “holle” Example 2: Input: s = “leetcode” Output: “leotcede” Constraints: 1 <= s.length <= 3 * 105 s consist of printable ASCII characters. Python Solution

[Solved] Given a string s, reverse only all the vowels in the string and return it. Read More »

Leetcode solutions MLP Feature Image

[Solved] Write a function that reverses a string. The input string is given as an array of characters s.

Question Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Example 1: Input: s = [“h”,”e”,”l”,”l”,”o”] Output: [“o”,”l”,”l”,”e”,”h”] Example 2: Input: s = [“H”,”a”,”n”,”n”,”a”,”h”] Output: [“h”,”a”,”n”,”n”,”a”,”H”] Constraints: 1 <= s.length <= 105 s[i] is a printable ascii character. Python

[Solved] Write a function that reverses a string. The input string is given as an array of characters s. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer n, return true if it is a power of four. Otherwise, return false.

Question Given an integer n, return true if it is a power of four. Otherwise, return false. An integer n is a power of four, if there exists an integer x such that n == 4x. Example 1: Input: n = 16 Output: true Example 2: Input: n = 5 Output: false Example 3: Input: n = 1 Output: true Constraints: -231 <= n <=

[Solved] Given an integer n, return true if it is a power of four. Otherwise, return false. Read More »

Scroll to Top