Leetcode Solutions

Leetcode solutions MLP Feature Image

[Solved] Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

Question Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since […]

[Solved] Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.

Question Given an integer num, repeatedly add all its digits until the result has only one digit, and return it. Example 1: Input: num = 38 Output: 2 Explanation: The process is 38 –> 3 + 8 –> 11 11 –> 1 + 1 –> 2 Since 2 has only one digit, return it. Example 2:

[Solved] Given an integer num, repeatedly add all its digits until the result has only one digit, and return it. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary tree, return all root-to-leaf paths in any order.

Question Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. Example 1: Input: root = [1,2,3,null,5] Output: [“1->2->5″,”1->3”] Example 2: Input: root = [1] Output: [“1”] Constraints: The number of nodes in the tree is in the range [1, 100]. -100 <= Node.val <= 100 Python Solution

[Solved] Given the root of a binary tree, return all root-to-leaf paths in any order. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two strings s and t, return true if t is an anagram of s, and false otherwise.

Question Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: s = “anagram”, t = “nagaram” Output: true Example 2: Input: s = “rat”, t = “car” Output: false

[Solved] Given two strings s and t, return true if t is an anagram of s, and false otherwise. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

Question You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. Example 1: Input: nums =

[Solved] You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

Question Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation. Example 1: Input: nums = [1,2,3,4] Output: [24,12,8,6] Example 2: Input: nums =

[Solved] Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. Read More »

Leetcode solutions MLP Feature Image

[Solved] There is a singly-linked list head and we want to delete a node node in it. You are given the node to be deleted node. You will not be given access to the first node of head.

Question There is a singly-linked list head and we want to delete a node node in it. You are given the node to be deleted node. You will not be given access to the first node of head. All the values of the linked list are unique, and it is guaranteed that the given node node is not the last node in the linked list. Delete

[Solved] There is a singly-linked list head and we want to delete a node node in it. You are given the node to be deleted node. You will not be given access to the first node of head. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the head of a singly linked list, return true if it is a palindrome or false otherwise.

Question Given the head of a singly linked list, return true if it is a palindrome or false otherwise. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false Constraints: The number of nodes in the list is in the range [1, 105]. 0 <= Node.val <= 9 Follow up: Could you do it in O(n) time and O(1) space? Python

[Solved] Given the head of a singly linked list, return true if it is a palindrome or false otherwise. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x.

Question Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x. Example 1: Input: n = 1 Output: true Explanation: 20 = 1 Example 2: Input: n = 16 Output: true Explanation: 24 = 16 Example 3: Input: n

[Solved] Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

Question Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Example 1: Input: root = [3,1,4,null,2], k = 1 Output: 1 Example 2: Input: root = [5,3,6,2,4,null,null,1], k = 3 Output: 3 Constraints: The number of nodes in the tree is n. 1

[Solved] Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Read More »

Scroll to Top