Category Leetcode Solution

Gray Code LeetCode Solution

Problem – Gray Code LeetCode Solution An n-bit gray code sequence is a sequence of 2n integers where: Every integer is in the inclusive range [0, 2n – 1], The first integer is 0, An integer appears no more than once in the sequence, The binary representation of every pair of adjacent integers…

View Answers

Subsets II LeetCode Solution

Problem – Subsets II LeetCode Solution Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Example 1: Example 2: Constraints: 1 <= nums.length <= 10…

View Answers

Reverse Linked List II LeetCode Solution

Problem – Reverse Linked List II LeetCode Solution Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list. Example 1: Example 2: Constraints: The number of…

View Answers

Restore IP Addresses LeetCode Solution

Problem – Restore IP Addresses LeetCode Solution A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros. For example, “0.1.2.201” and “192.168.1.1” are valid IP addresses, but “0.011.255.245”, “192.168.1.312” and “[email protected]” are invalid IP addresses. Given a string s containing only digits, return all possible valid…

View Answers

Unique Binary Search Trees LeetCode Solution

Problem – Unique Binary Search Trees LeetCode Solution Given an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n. Example 1: Example 2: Constraints: 1 <= n <= 19 Unique Binary Search Trees…

View Answers

Interleaving String LeetCode Solution

Problem – Interleaving String LeetCode Solution Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2. An interleaving of two strings s and t is a configuration where s and t are divided into n and m non-empty substrings respectively, such that: s = s1 + s2 + … + sn t = t1 + t2 + … + tm |n…

View Answers