diff --git a/LeetCodeNet/G0001_0100/S0048_rotate_image/readme.md b/LeetCodeNet/G0001_0100/S0048_rotate_image/readme.md new file mode 100644 index 0000000..7b589bf --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0048_rotate_image/readme.md @@ -0,0 +1,66 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 48\. Rotate Image + +Medium + +You are given an `n x n` 2D `matrix` representing an image, rotate the image by **90** degrees (clockwise). + +You have to rotate the image [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm), which means you have to modify the input 2D matrix directly. **DO NOT** allocate another 2D matrix and do the rotation. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/08/28/mat1.jpg) + +**Input:** matrix = \[\[1,2,3],[4,5,6],[7,8,9]] + +**Output:** [[7,4,1],[8,5,2],[9,6,3]] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/08/28/mat2.jpg) + +**Input:** matrix = \[\[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] + +**Output:** [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]] + +**Example 3:** + +**Input:** matrix = \[\[1]] + +**Output:** [[1]] + +**Example 4:** + +**Input:** matrix = \[\[1,2],[3,4]] + +**Output:** [[3,1],[4,2]] + +**Constraints:** + +* `matrix.length == n` +* `matrix[i].length == n` +* `1 <= n <= 20` +* `-1000 <= matrix[i][j] <= 1000` + +## Solution + +```csharp +public class Solution { + public void Rotate(int[][] matrix) { + (int height, int width) = (matrix.Length, matrix[0].Length); + for (int row = 0; row < height - 1; row++) { + for (int col = row + 1; col < width; col++) { + (matrix[col][row], matrix[row][col]) = (matrix[row][col], matrix[col][row]); + } + } + for (int col = 0; col < width / 2; col++) { + int oppositeCol = width - 1 - col; + for (int row = 0; row < height; row++) { + (matrix[row][col], matrix[row][oppositeCol]) = (matrix[row][oppositeCol], matrix[row][col]); + } + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0049_group_anagrams/readme.md b/LeetCodeNet/G0001_0100/S0049_group_anagrams/readme.md new file mode 100644 index 0000000..9767a56 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0049_group_anagrams/readme.md @@ -0,0 +1,57 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 49\. Group Anagrams + +Medium + +Given an array of strings `strs`, group **the anagrams** together. You can return the answer in **any order**. + +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:** strs = ["eat","tea","tan","ate","nat","bat"] + +**Output:** [["bat"],["nat","tan"],["ate","eat","tea"]] + +**Example 2:** + +**Input:** strs = [""] + +**Output:** [[""]] + +**Example 3:** + +**Input:** strs = ["a"] + +**Output:** [["a"]] + +**Constraints:** + +* 1 <= strs.length <= 104 +* `0 <= strs[i].length <= 100` +* `strs[i]` consists of lowercase English letters. + +## Solution + +```csharp +public class Solution { + public IList> GroupAnagrams(string[] strs) { + var map = new Dictionary>(); + // allocate memory only once and reuse it to sort the chars of each s in strs. + var buffer = new char[10000]; + var bufferSpan = new Span(buffer); + foreach (var s in strs) { + s.CopyTo(bufferSpan); + Array.Sort(buffer, 0, s.Length); + var key = new string(buffer, 0, s.Length); + if (!map.TryGetValue(key, out var value)) { + map[key] = value = new List(); + } + value.Add(s); + } + return map.Values.Cast>().ToList(); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0051_n_queens/readme.md b/LeetCodeNet/G0001_0100/S0051_n_queens/readme.md new file mode 100644 index 0000000..bb2b2bb --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0051_n_queens/readme.md @@ -0,0 +1,65 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 51\. N-Queens + +Hard + +The **n-queens** puzzle is the problem of placing `n` queens on an `n x n` chessboard such that no two queens attack each other. + +Given an integer `n`, return _all distinct solutions to the **n-queens puzzle**_. You may return the answer in **any order**. + +Each solution contains a distinct board configuration of the n-queens' placement, where `'Q'` and `'.'` both indicate a queen and an empty space, respectively. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/13/queens.jpg) + +**Input:** n = 4 + +**Output:** [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]] + +**Explanation:** There exist two distinct solutions to the 4-queens puzzle as shown above + +**Example 2:** + +**Input:** n = 1 + +**Output:** [["Q"]] + +**Constraints:** + +* `1 <= n <= 9` + +## Solution + +```csharp +public class Solution { + public IList> SolveNQueens(int n) { + return this.Backtrack(n, 0, (x, y) => false).ToList(); + } + + private IEnumerable> Backtrack(int boardSize, int y, Func check) { + for (int x = 0; x < boardSize; x++) { + if (check(x, y)) { + continue; + } + string currentLine = $"{new string('.', x)}Q{new string('.', boardSize - x - 1)}"; + if (y == boardSize - 1) { + yield return new List { currentLine }; + continue; + } + var results = this.Backtrack(boardSize, y + 1, (xx, yy) => + check(xx, yy) || + (xx == x) || + (yy == (y - x) + xx) || + (yy == (x + y) - xx) + ); + foreach (var result in results) { + result.Add(currentLine); + yield return result; + } + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0053_maximum_subarray/readme.md b/LeetCodeNet/G0001_0100/S0053_maximum_subarray/readme.md new file mode 100644 index 0000000..119b9b0 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0053_maximum_subarray/readme.md @@ -0,0 +1,56 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 53\. Maximum Subarray + +Easy + +Given an integer array `nums`, find the contiguous subarray (containing at least one number) which has the largest sum and return _its sum_. + +A **subarray** is a **contiguous** part of an array. + +**Example 1:** + +**Input:** nums = [-2,1,-3,4,-1,2,1,-5,4] + +**Output:** 6 + +**Explanation:** [4,-1,2,1] has the largest sum = 6. + +**Example 2:** + +**Input:** nums = [1] + +**Output:** 1 + +**Example 3:** + +**Input:** nums = [5,4,-1,7,8] + +**Output:** 23 + +**Constraints:** + +* 1 <= nums.length <= 105 +* -104 <= nums[i] <= 104 + +**Follow up:** If you have figured out the `O(n)` solution, try coding another solution using the **divide and conquer** approach, which is more subtle. + +## Solution + +```csharp +public class Solution { + public int MaxSubArray(int[] nums) { + int maxSum = nums[0]; + int curSum = 0; + for (int i = 0; i < nums.Length; i++) { + curSum += nums[i]; + maxSum = Math.Max(curSum, maxSum); + if (curSum < 0) { + curSum = 0; + } + } + return maxSum; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0055_jump_game/readme.md b/LeetCodeNet/G0001_0100/S0055_jump_game/readme.md new file mode 100644 index 0000000..adf0daf --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0055_jump_game/readme.md @@ -0,0 +1,51 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 55\. Jump Game + +Medium + +You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position. + +Return `true` _if you can reach the last index, or_ `false` _otherwise_. + +**Example 1:** + +**Input:** nums = [2,3,1,1,4] + +**Output:** true + +**Explanation:** Jump 1 step from index 0 to 1, then 3 steps to the last index. + +**Example 2:** + +**Input:** nums = [3,2,1,0,4] + +**Output:** false + +**Explanation:** You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index. + +**Constraints:** + +* 1 <= nums.length <= 104 +* 0 <= nums[i] <= 105 + +## Solution + +```csharp +public class Solution { + public bool CanJump(int[] nums) { + var accumulatedJumps = 0; + for (var i = 0; i < nums.Length; i++) { + if (i > accumulatedJumps) { + return false; + } + if (accumulatedJumps >= nums.Length - 1) { + return true; + } + accumulatedJumps = Math.Max(accumulatedJumps, i + nums[i]); + } + return false; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0056_merge_intervals/readme.md b/LeetCodeNet/G0001_0100/S0056_merge_intervals/readme.md new file mode 100644 index 0000000..bed126a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0056_merge_intervals/readme.md @@ -0,0 +1,48 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 56\. Merge Intervals + +Medium + +Given an array of `intervals` where intervals[i] = [starti, endi], merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_. + +**Example 1:** + +**Input:** intervals = \[\[1,3],[2,6],[8,10],[15,18]] + +**Output:** [[1,6],[8,10],[15,18]] + +**Explanation:** Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. + +**Example 2:** + +**Input:** intervals = \[\[1,4],[4,5]] + +**Output:** [[1,5]] + +**Explanation:** Intervals [1,4] and [4,5] are considered overlapping. + +**Constraints:** + +* 1 <= intervals.length <= 104 +* `intervals[i].length == 2` +* 0 <= starti <= endi <= 104 + +## Solution + +```csharp +public class Solution { + public int[][] Merge(int[][] intervals) { + Array.Sort(intervals, (a, b) => a[0] - b[0]); + for (int i = 1; i < intervals.Length; i++) { + if (intervals[i][0] <= intervals[i - 1][1]) { + intervals[i][0] = intervals[i - 1][0]; + intervals[i][1] = Math.Max(intervals[i - 1][1], intervals[i][1]); + intervals[i - 1][0] = -1; + } + } + return intervals.Where(obj => obj[0] != -1).ToArray(); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0062_unique_paths/readme.md b/LeetCodeNet/G0001_0100/S0062_unique_paths/readme.md new file mode 100644 index 0000000..1d4c3f6 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0062_unique_paths/readme.md @@ -0,0 +1,69 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 62\. Unique Paths + +Medium + +A robot is located at the top-left corner of a `m x n` grid (marked 'Start' in the diagram below). + +The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). + +How many possible unique paths are there? + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/10/22/robot_maze.png) + +**Input:** m = 3, n = 7 + +**Output:** 28 + +**Example 2:** + +**Input:** m = 3, n = 2 + +**Output:** 3 + +**Explanation:** + + From the top-left corner, there are a total of 3 ways to reach the bottom-right corner: + 1. Right -> Down -> Down + 2. Down -> Down -> Right + 3. Down -> Right -> Down + +**Example 3:** + +**Input:** m = 7, n = 3 + +**Output:** 28 + +**Example 4:** + +**Input:** m = 3, n = 3 + +**Output:** 6 + +**Constraints:** + +* `1 <= m, n <= 100` +* It's guaranteed that the answer will be less than or equal to 2 * 109. + +## Solution + +```csharp +public class Solution { + public int UniquePaths(int m, int n) { + int[] array = new int[n]; + for (int i = 0; i < n; i++) { + array[i] = 1; + } + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + array[j] = array[j] + array[j - 1]; + } + } + return array[n - 1]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/readme.md b/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/readme.md new file mode 100644 index 0000000..232b4ea --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/readme.md @@ -0,0 +1,56 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 64\. Minimum Path Sum + +Medium + +Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. + +**Note:** You can only move either down or right at any point in time. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/05/minpath.jpg) + +**Input:** grid = \[\[1,3,1],[1,5,1],[4,2,1]] + +**Output:** 7 + +**Explanation:** Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum. + +**Example 2:** + +**Input:** grid = \[\[1,2,3],[4,5,6]] + +**Output:** 12 + +**Constraints:** + +* `m == grid.length` +* `n == grid[i].length` +* `1 <= m, n <= 200` +* `0 <= grid[i][j] <= 100` + +## Solution + +```csharp +public class Solution { + public int MinPathSum(int[][] grid) { + int m = grid.Length; + int n = grid[0].Length; + for (int i = 1; i < n; i++) { + grid[0][i] += grid[0][i - 1]; + } + for (int i = 1; i < m; i++) { + grid[i][0] += grid[i - 1][0]; + } + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + grid[i][j] += Math.Min(grid[i][j - 1], grid[i - 1][j]); + } + } + return grid[m - 1][n - 1]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0070_climbing_stairs/readme.md b/LeetCodeNet/G0001_0100/S0070_climbing_stairs/readme.md new file mode 100644 index 0000000..2c2b3d6 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0070_climbing_stairs/readme.md @@ -0,0 +1,50 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 70\. Climbing Stairs + +Easy + +You are climbing a staircase. It takes `n` steps to reach the top. + +Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top? + +**Example 1:** + +**Input:** n = 2 + +**Output:** 2 + +**Explanation:** There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps + +**Example 2:** + +**Input:** n = 3 + +**Output:** 3 + +**Explanation:** There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2. 1 step + 2 steps 3. 2 steps + 1 step + +**Constraints:** + +* `1 <= n <= 45` + +## Solution + +```csharp +public class Solution { + public int ClimbStairs(int n) { + int[] dp = new int[n + 1]; + dp[0] = 1; + for (int i = 0; i < dp.Length; i++) { + if (i + 1 < dp.Length) { + dp[i + 1] += dp[i]; + } + if (i + 2 < dp.Length) { + dp[i + 2] += dp[i]; + } + } + return dp[dp.Length - 1]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0072_edit_distance/readme.md b/LeetCodeNet/G0001_0100/S0072_edit_distance/readme.md new file mode 100644 index 0000000..71460e1 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0072_edit_distance/readme.md @@ -0,0 +1,59 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 72\. Edit Distance + +Hard + +Given two strings `word1` and `word2`, return _the minimum number of operations required to convert `word1` to `word2`_. + +You have the following three operations permitted on a word: + +* Insert a character +* Delete a character +* Replace a character + +**Example 1:** + +**Input:** word1 = "horse", word2 = "ros" + +**Output:** 3 + +**Explanation:** horse -> rorse (replace 'h' with 'r') rorse -> rose (remove 'r') rose -> ros (remove 'e') + +**Example 2:** + +**Input:** word1 = "intention", word2 = "execution" + +**Output:** 5 + +**Explanation:** intention -> inention (remove 't') inention -> enention (replace 'i' with 'e') enention -> exention (replace 'n' with 'x') exention -> exection (replace 'n' with 'c') exection -> execution (insert 'u') + +**Constraints:** + +* `0 <= word1.length, word2.length <= 500` +* `word1` and `word2` consist of lowercase English letters. + +## Solution + +```csharp +public class Solution { + public int MinDistance(string word1, string word2) { + var map = new int[word1.Length + 1, word2.Length + 1]; + for (int i = 0; i <= word1.Length; i++) { + map[i, 0] = i; + } + for (int i = 0; i <= word2.Length; i++) { + map[0, i] = i; + } + for (int i = 1; i <= word1.Length; i++) { + for (var j = 1; j <= word2.Length; j++) { + var add = word1[i - 1] == word2[j - 1] ? 0 : 1; + var min = Math.Min(map[i - 1, j] + 1, map[i, j - 1] + 1); + map[i, j] = Math.Min(min, map[i - 1, j - 1] + add); + } + } + return map[word1.Length, word2.Length]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/readme.md b/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/readme.md new file mode 100644 index 0000000..16dd2a9 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/readme.md @@ -0,0 +1,97 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 73\. Set Matrix Zeroes + +Medium + +Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s, and return _the matrix_. + +You must do it [in place](https://en.wikipedia.org/wiki/In-place_algorithm). + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg) + +**Input:** matrix = \[\[1,1,1],[1,0,1],[1,1,1]] + +**Output:** [[1,0,1],[0,0,0],[1,0,1]] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg) + +**Input:** matrix = \[\[0,1,2,0],[3,4,5,2],[1,3,1,5]] + +**Output:** [[0,0,0,0],[0,4,5,0],[0,3,1,0]] + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[0].length` +* `1 <= m, n <= 200` +* -231 <= matrix[i][j] <= 231 - 1 + +**Follow up:** + +* A straightforward solution using `O(mn)` space is probably a bad idea. +* A simple improvement uses `O(m + n)` space, but still not the best solution. +* Could you devise a constant space solution? + +## Solution + +```csharp +public class Solution { + // Approach: Use first row and first column for storing whether in future + // the entire row or column needs to be marked 0 + public void SetZeroes(int[][] matrix) { + int m = matrix.Length; + int n = matrix[0].Length; + bool row0 = false; + bool col0 = false; + // Check if 0th col needs to be market all 0s in future + foreach (int[] ints in matrix) { + if (ints[0] == 0) { + col0 = true; + break; + } + } + // Check if 0th row needs to be market all 0s in future + for (int i = 0; i < n; i++) { + if (matrix[0][i] == 0) { + row0 = true; + break; + } + } + // Store the signals in 0th row and column + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + if (matrix[i][j] == 0) { + matrix[i][0] = 0; + matrix[0][j] = 0; + } + } + } + // Mark 0 for all cells based on signal from 0th row and 0th column + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + if (matrix[i][0] == 0 || matrix[0][j] == 0) { + matrix[i][j] = 0; + } + } + } + // Set 0th column + for (int i = 0; i < m; i++) { + if (col0) { + matrix[i][0] = 0; + } + } + // Set 0th row + for (int i = 0; i < n; i++) { + if (row0) { + matrix[0][i] = 0; + } + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/readme.md b/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/readme.md new file mode 100644 index 0000000..ac2871a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/readme.md @@ -0,0 +1,60 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 74\. Search a 2D Matrix + +Medium + +Write an efficient algorithm that searches for a value in an `m x n` matrix. This matrix has the following properties: + +* Integers in each row are sorted from left to right. +* The first integer of each row is greater than the last integer of the previous row. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/05/mat.jpg) + +**Input:** matrix = \[\[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/10/05/mat2.jpg) + +**Input:** matrix = \[\[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13 + +**Output:** false + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= m, n <= 100` +* -104 <= matrix[i][j], target <= 104 + +## Solution + +```csharp +public class Solution { + public bool SearchMatrix(int[][] matrix, int target) { + int endRow = matrix.Length; + int endCol = matrix[0].Length; + int targetRow = 0; + bool result = false; + for (int i = 0; i < endRow; i++) { + if (matrix[i][endCol - 1] >= target) { + targetRow = i; + break; + } + } + for (int i = 0; i < endCol; i++) { + if (matrix[targetRow][i] == target) { + result = true; + break; + } + } + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0075_sort_colors/readme.md b/LeetCodeNet/G0001_0100/S0075_sort_colors/readme.md new file mode 100644 index 0000000..0e5a1a6 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0075_sort_colors/readme.md @@ -0,0 +1,68 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 75\. Sort Colors + +Medium + +Given an array `nums` with `n` objects colored red, white, or blue, sort them **[in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** so that objects of the same color are adjacent, with the colors in the order red, white, and blue. + +We will use the integers `0`, `1`, and `2` to represent the color red, white, and blue, respectively. + +You must solve this problem without using the library's sort function. + +**Example 1:** + +**Input:** nums = [2,0,2,1,1,0] + +**Output:** [0,0,1,1,2,2] + +**Example 2:** + +**Input:** nums = [2,0,1] + +**Output:** [0,1,2] + +**Example 3:** + +**Input:** nums = [0] + +**Output:** [0] + +**Example 4:** + +**Input:** nums = [1] + +**Output:** [1] + +**Constraints:** + +* `n == nums.length` +* `1 <= n <= 300` +* `nums[i]` is `0`, `1`, or `2`. + +**Follow up:** Could you come up with a one-pass algorithm using only constant extra space? + +## Solution + +```csharp +public class Solution { + public void SortColors(int[] nums) { + int zeroes = 0; + int ones = 0; + for (int i = 0; i < nums.Length; i++) { + if (nums[i] == 0) { + nums[zeroes++] = 0; + } else if (nums[i] == 1) { + ones++; + } + } + for (int j = zeroes; j < zeroes + ones; j++) { + nums[j] = 1; + } + for (int k = zeroes + ones; k < nums.Length; k++) { + nums[k] = 2; + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/readme.md b/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/readme.md new file mode 100644 index 0000000..5b681f5 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/readme.md @@ -0,0 +1,78 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 76\. Minimum Window Substring + +Hard + +Given two strings `s` and `t` of lengths `m` and `n` respectively, return _the **minimum window substring** of_ `s` _such that every character in_ `t` _(**including duplicates**) is included in the window. If there is no such substring__, return the empty string_ `""`_._ + +The testcases will be generated such that the answer is **unique**. + +A **substring** is a contiguous sequence of characters within the string. + +**Example 1:** + +**Input:** s = "ADOBECODEBANC", t = "ABC" + +**Output:** "BANC" + +**Explanation:** The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t. + +**Example 2:** + +**Input:** s = "a", t = "a" + +**Output:** "a" + +**Explanation:** The entire string s is the minimum window. + +**Example 3:** + +**Input:** s = "a", t = "aa" + +**Output:** "" + +**Explanation:** Both 'a's from t must be included in the window. Since the largest window of s only has one 'a', return empty string. + +**Constraints:** + +* `m == s.length` +* `n == t.length` +* 1 <= m, n <= 105 +* `s` and `t` consist of uppercase and lowercase English letters. + +**Follow up:** Could you find an algorithm that runs in `O(m + n)` time? + +## Solution + +```csharp +public class Solution { + public string MinWindow(string s, string t) { + int[] map = new int[128]; + foreach (char c in t) { + map[c - 'A']++; + } + int count = t.Length; + int begin = 0; + int end = 0; + int d = int.MaxValue; + int head = 0; + while (end < s.Length) { + if (map[s[end++] - 'A']-- > 0) { + count--; + } + while (count == 0) { + if (end - begin < d) { + d = end - begin; + head = begin; + } + if (map[s[begin++] - 'A']++ == 0) { + count++; + } + } + } + return d == int.MaxValue ? "" : s.Substring(head, d); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0078_subsets/readme.md b/LeetCodeNet/G0001_0100/S0078_subsets/readme.md new file mode 100644 index 0000000..fb1ffc1 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0078_subsets/readme.md @@ -0,0 +1,51 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 78\. Subsets + +Medium + +Given an integer array `nums` of **unique** elements, return _all possible subsets (the power set)_. + +The solution set **must not** contain duplicate subsets. Return the solution in **any order**. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] + +**Example 2:** + +**Input:** nums = [0] + +**Output:** [[],[0]] + +**Constraints:** + +* `1 <= nums.length <= 10` +* `-10 <= nums[i] <= 10` +* All the numbers of `nums` are **unique**. + +## Solution + +```csharp +using System.Collections.Generic; + +public class Solution { + public IList> Subsets(int[] nums) { + IList> res = new List>(); + Solve(nums, new List(), res, 0); + return res; + } + + private void Solve(int[] nums, List temp, IList> res, int start) { + res.Add(new List(temp)); + for (int i = start; i < nums.Length; i++) { + temp.Add(nums[i]); + Solve(nums, temp, res, i + 1); + temp.RemoveAt(temp.Count - 1); + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0079_word_search/readme.md b/LeetCodeNet/G0001_0100/S0079_word_search/readme.md new file mode 100644 index 0000000..7e87ef5 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0079_word_search/readme.md @@ -0,0 +1,88 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 79\. Word Search + +Medium + +Given an `m x n` grid of characters `board` and a string `word`, return `true` _if_ `word` _exists in the grid_. + +The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/04/word2.jpg) + +**Input:** board = \[\["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/04/word-1.jpg) + +**Input:** board = \[\["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE" + +**Output:** true + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2020/10/15/word3.jpg) + +**Input:** board = \[\["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB" + +**Output:** false + +**Constraints:** + +* `m == board.length` +* `n = board[i].length` +* `1 <= m, n <= 6` +* `1 <= word.length <= 15` +* `board` and `word` consists of only lowercase and uppercase English letters. + +**Follow up:** Could you use search pruning to make your solution faster with a larger `board`? + +## Solution + +```csharp +public class Solution { + public bool Exist(char[][] board, string word) { + for (int i = 0; i < board.Length; i++) { + for (int j = 0; j < board[0].Length; j++) { + char ch = word[0]; + if (board[i][j] == ch) { + if (helper(i, j, board, word, 1)) { + return true; + } + } + } + } + return false; + } + + private bool helper(int r, int c, char[][] board, string word, int count) { + if (count == word.Length) { + return true; + } + char currChar = board[r][c]; + board[r][c] = '!'; + char nextChar = word[count]; + + if (r > 0 && board[r - 1][c] == nextChar) { + if (helper(r - 1, c, board, word, count + 1)) return true; + } + if (r < board.Length - 1 && board[r + 1][c] == nextChar) { + if (helper(r + 1, c, board, word, count + 1)) return true; + } + if (c > 0 && board[r][c - 1] == nextChar) { + if (helper(r, c - 1, board, word, count + 1)) return true; + } + if (c < board[0].Length - 1 && board[r][c + 1] == nextChar) { + if (helper(r, c + 1, board, word, count + 1)) return true; + } + board[r][c] = currChar; + return false; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/readme.md b/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/readme.md new file mode 100644 index 0000000..96b6f17 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/readme.md @@ -0,0 +1,56 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 84\. Largest Rectangle in Histogram + +Hard + +Given an array of integers `heights` representing the histogram's bar height where the width of each bar is `1`, return _the area of the largest rectangle in the histogram_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/04/histogram.jpg) + +**Input:** heights = [2,1,5,6,2,3] + +**Output:** 10 + +**Explanation:** The above is a histogram where width of each bar is 1. The largest rectangle is shown in the red area, which has an area = 10 units. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/01/04/histogram-1.jpg) + +**Input:** heights = [2,4] + +**Output:** 4 + +**Constraints:** + +* 1 <= heights.length <= 105 +* 0 <= heights[i] <= 104 + +## Solution + +```csharp +public class Solution { + public int LargestRectangleArea(int[] heights) { + int maxArea = 0, i = 0; + Stack stack = new Stack(); + while (i <= heights.Length) { + var currHeight = i == heights.Length ? 0 : heights[i]; + if (!stack.Any() || currHeight >= heights[stack.Peek()]) { + stack.Push(i); + i++; + } + else { + int index = stack.Pop(); + int height = heights[index]; + int width = (!stack.Any()) ? i : (i - 1) - stack.Peek(); + maxArea = Math.Max(maxArea, height * width); + } + } + return maxArea; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/readme.md b/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/readme.md new file mode 100644 index 0000000..83faf88 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/readme.md @@ -0,0 +1,94 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 94\. Binary Tree Inorder Traversal + +Easy + +Given the `root` of a binary tree, return _the inorder traversal of its nodes' values_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg) + +**Input:** root = [1,null,2,3] + +**Output:** [1,3,2] + +**Example 2:** + +**Input:** root = [] + +**Output:** [] + +**Example 3:** + +**Input:** root = [1] + +**Output:** [1] + +**Example 4:** + +![](https://assets.leetcode.com/uploads/2020/09/15/inorder_5.jpg) + +**Input:** root = [1,2] + +**Output:** [2,1] + +**Example 5:** + +![](https://assets.leetcode.com/uploads/2020/09/15/inorder_4.jpg) + +**Input:** root = [1,null,2] + +**Output:** [1,2] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 100]`. +* `-100 <= Node.val <= 100` + +**Follow up:** Recursive solution is trivial, could you do it iteratively? + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for a binary tree node. + * public class TreeNode { + * public int val; + * public TreeNode left; + * public TreeNode right; + * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +public class Solution { + public IList InorderTraversal(TreeNode root) { + if (root == null) { + return new List(); + } + var answer = new List(); + InorderTraversal(root, answer); + return answer; + } + + private void InorderTraversal(TreeNode root, IList answer) { + if (root == null) { + return; + } + if (root.left != null) { + InorderTraversal(root.left, answer); + } + answer.Add((int)root.val); + if (root.right != null) { + InorderTraversal(root.right, answer); + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/readme.md b/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/readme.md new file mode 100644 index 0000000..bf58a48 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/readme.md @@ -0,0 +1,42 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 96\. Unique Binary Search Trees + +Medium + +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:** + +![](https://assets.leetcode.com/uploads/2021/01/18/uniquebstn3.jpg) + +**Input:** n = 3 + +**Output:** 5 + +**Example 2:** + +**Input:** n = 1 + +**Output:** 1 + +**Constraints:** + +* `1 <= n <= 19` + +## Solution + +```csharp +public class Solution { + public int NumTrees(int n) { + long result = 1; + for (int i = 0; i < n; i++) { + result *= 2L * n - i; + result /= i + 1; + } + result /= n + 1; + return (int) result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/readme.md b/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/readme.md new file mode 100644 index 0000000..84dca86 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/readme.md @@ -0,0 +1,73 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 98\. Validate Binary Search Tree + +Medium + +Given the `root` of a binary tree, _determine if it is a valid binary search tree (BST)_. + +A **valid BST** is defined as follows: + +* The left subtree of a node contains only nodes with keys **less than** the node's key. +* The right subtree of a node contains only nodes with keys **greater than** the node's key. +* Both the left and right subtrees must also be binary search trees. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg) + +**Input:** root = [2,1,3] + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg) + +**Input:** root = [5,1,4,null,null,3,6] + +**Output:** false + +**Explanation:** The root node's value is 5 but its right child's value is 4. + +**Constraints:** + +* The number of nodes in the tree is in the range [1, 104]. +* -231 <= Node.val <= 231 - 1 + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for a binary tree node. + * public class TreeNode { + * public int val; + * public TreeNode left; + * public TreeNode right; + * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +public class Solution { + public bool IsValidBST(TreeNode root) { + return Solve(root, long.MinValue, long.MaxValue); + } + // we will send a valid range and check whether the root lies in the range + // and update the range for the subtrees + private bool Solve(TreeNode root, long left, long right) { + if (root == null) { + return true; + } + if (root.val <= left || root.val >= right) { + return false; + } + return Solve(root.left, left, (long)root.val) && Solve(root.right, (long)root.val, right); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0101_symmetric_tree/readme.md b/LeetCodeNet/G0101_0200/S0101_symmetric_tree/readme.md new file mode 100644 index 0000000..617283b --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0101_symmetric_tree/readme.md @@ -0,0 +1,69 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 101\. Symmetric Tree + +Easy + +Given the `root` of a binary tree, _check whether it is a mirror of itself_ (i.e., symmetric around its center). + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg) + +**Input:** root = [1,2,2,3,4,4,3] + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/19/symtree2.jpg) + +**Input:** root = [1,2,2,null,3,null,3] + +**Output:** false + +**Constraints:** + +* The number of nodes in the tree is in the range `[1, 1000]`. +* `-100 <= Node.val <= 100` + +**Follow up:** Could you solve it both recursively and iteratively? + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for a binary tree node. + * public class TreeNode { + * public int val; + * public TreeNode left; + * public TreeNode right; + * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +public class Solution { + public bool IsSymmetric(TreeNode root) { + if (root == null) { + return true; + } + return Helper(root.left, root.right); + } + + private bool Helper(TreeNode leftNode, TreeNode rightNode) { + if (leftNode == null || rightNode == null) { + return leftNode == null && rightNode == null; + } + if (leftNode.val != rightNode.val) { + return false; + } + return Helper(leftNode.left, rightNode.right) && Helper(leftNode.right, rightNode.left); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/readme.md b/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/readme.md new file mode 100644 index 0000000..650b6d7 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/readme.md @@ -0,0 +1,91 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 239\. Sliding Window Maximum + +Hard + +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 = [1,3,-1,-3,5,3,6,7], k = 3 + +**Output:** [3,3,5,5,6,7] + +**Explanation:** + + Window position Max + --------------- ----- + [1 3 -1] -3 5 3 6 7 3 + 1 [3 -1 -3] 5 3 6 7 3 + 1 3 [-1 -3 5] 3 6 7 5 + 1 3 -1 [-3 5 3] 6 7 5 + 1 3 -1 -3 [5 3 6] 7 6 + 1 3 -1 -3 5 [3 6 7] 7 + +**Example 2:** + +**Input:** nums = [1], k = 1 + +**Output:** [1] + +**Example 3:** + +**Input:** nums = [1,-1], k = 1 + +**Output:** [1,-1] + +**Example 4:** + +**Input:** nums = [9,11], k = 2 + +**Output:** [11] + +**Example 5:** + +**Input:** nums = [4,-2], k = 2 + +**Output:** [4] + +**Constraints:** + +* 1 <= nums.length <= 105 +* -104 <= nums[i] <= 104 +* `1 <= k <= nums.length` + +## Solution + +```csharp +using System; +using System.Collections.Generic; + +public class Solution { + public int[] MaxSlidingWindow(int[] nums, int k) { + int n = nums.Length; + int[] res = new int[n - k + 1]; + int x = 0; + LinkedList dq = new LinkedList(); + int i = 0; + int j = 0; + while (j < nums.Length) { + while (dq.Count != 0 && dq.Last.Value < nums[j]) { + dq.RemoveLast(); + } + dq.AddLast(nums[j]); + if (j - i + 1 == k) { + res[x] = dq.First.Value; + ++x; + if (dq.First.Value == nums[i]) { + dq.RemoveFirst(); + } + ++i; + } + ++j; + } + return res; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/readme.md b/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/readme.md new file mode 100644 index 0000000..72a54ee --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/readme.md @@ -0,0 +1,58 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 240\. Search a 2D Matrix II + +Medium + +Write an efficient algorithm that searches for a `target` value in an `m x n` integer `matrix`. The `matrix` has the following properties: + +* Integers in each row are sorted in ascending from left to right. +* Integers in each column are sorted in ascending from top to bottom. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/24/searchgrid2.jpg) + +**Input:** matrix = \[\[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5 + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/24/searchgrid.jpg) + +**Input:** matrix = \[\[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20 + +**Output:** false + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= n, m <= 300` +* -109 <= matrix[i][j] <= 109 +* All the integers in each row are **sorted** in ascending order. +* All the integers in each column are **sorted** in ascending order. +* -109 <= target <= 109 + +## Solution + +```csharp +public class Solution { + public bool SearchMatrix(int[][] matrix, int target) { + int r = 0; + int c = matrix[0].Length - 1; + while (r < matrix.Length && c >= 0) { + if (matrix[r][c] == target) { + return true; + } else if (matrix[r][c] > target) { + c--; + } else { + r++; + } + } + return false; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0283_move_zeroes/readme.md b/LeetCodeNet/G0201_0300/S0283_move_zeroes/readme.md new file mode 100644 index 0000000..10e591d --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0283_move_zeroes/readme.md @@ -0,0 +1,51 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 283\. Move Zeroes + +Easy + +Given an integer array `nums`, move all `0`'s to the end of it while maintaining the relative order of the non-zero elements. + +**Note** that you must do this in-place without making a copy of the array. + +**Example 1:** + +**Input:** nums = [0,1,0,3,12] + +**Output:** [1,3,12,0,0] + +**Example 2:** + +**Input:** nums = [0] + +**Output:** [0] + +**Constraints:** + +* 1 <= nums.length <= 104 +* -231 <= nums[i] <= 231 - 1 + +**Follow up:** Could you minimize the total number of operations done? + +## Solution + +```csharp +public class Solution { + public void MoveZeroes(int[] nums) { + int firstZero = 0; + for (int i = 0; i < nums.Length; i++) { + if (nums[i] != 0) { + Swap(firstZero, i, nums); + firstZero++; + } + } + } + + private void Swap(int index1, int index2, int[] numbers) { + int val2 = numbers[index2]; + numbers[index2] = numbers[index1]; + numbers[index1] = val2; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/readme.md b/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/readme.md new file mode 100644 index 0000000..2ecc34a --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/readme.md @@ -0,0 +1,65 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 287\. Find the Duplicate Number + +Medium + +Given an array of integers `nums` containing `n + 1` integers where each integer is in the range `[1, n]` inclusive. + +There is only **one repeated number** in `nums`, return _this repeated number_. + +You must solve the problem **without** modifying the array `nums` and uses only constant extra space. + +**Example 1:** + +**Input:** nums = [1,3,4,2,2] + +**Output:** 2 + +**Example 2:** + +**Input:** nums = [3,1,3,4,2] + +**Output:** 3 + +**Example 3:** + +**Input:** nums = [1,1] + +**Output:** 1 + +**Example 4:** + +**Input:** nums = [1,1,2] + +**Output:** 1 + +**Constraints:** + +* 1 <= n <= 105 +* `nums.length == n + 1` +* `1 <= nums[i] <= n` +* All the integers in `nums` appear only **once** except for **precisely one integer** which appears **two or more** times. + +**Follow up:** + +* How can we prove that at least one duplicate number must exist in `nums`? +* Can you solve the problem in linear runtime complexity? + +## Solution + +```csharp +public class Solution { + public int FindDuplicate(int[] nums) { + int[] arr = new int[nums.Length + 1]; + foreach (int num in nums) { + arr[num] += 1; + if (arr[num] == 2) { + return num; + } + } + return 0; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/readme.md b/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/readme.md new file mode 100644 index 0000000..7f2e3c4 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/readme.md @@ -0,0 +1,79 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 295\. Find Median from Data Stream + +Hard + +The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. + +* For example, for `arr = [2,3,4]`, the median is `3`. +* For example, for `arr = [2,3]`, the median is `(2 + 3) / 2 = 2.5`. + +Implement the MedianFinder class: + +* `MedianFinder()` initializes the `MedianFinder` object. +* `void addNum(int num)` adds the integer `num` from the data stream to the data structure. +* `double findMedian()` returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted. + +**Example 1:** + +**Input** + + ["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"] + [[], [1], [2], [], [3], []] + +**Output:** [null, null, null, 1.5, null, 2.0] + +**Explanation:** + + MedianFinder medianFinder = new MedianFinder(); + medianFinder.addNum(1); // arr = [1] + medianFinder.addNum(2); // arr = [1, 2] + medianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2) + medianFinder.addNum(3); // arr[1, 2, 3] + medianFinder.findMedian(); // return 2.0 + +**Constraints:** + +* -105 <= num <= 105 +* There will be at least one element in the data structure before calling `findMedian`. +* At most 5 * 104 calls will be made to `addNum` and `findMedian`. + +**Follow up:** + +* If all integer numbers from the stream are in the range `[0, 100]`, how would you optimize your solution? +* If `99%` of all integer numbers from the stream are in the range `[0, 100]`, how would you optimize your solution? + +## Solution + +```csharp +using System; +using System.Collections.Generic; + +public class MedianFinder { + private PriorityQueue left = new(); + private PriorityQueue right = new(); + private bool odd = false; + + public void AddNum(int n) { + odd = !odd; + int m = right.EnqueueDequeue(n, -n); + left.Enqueue(m, m); + if (left.Count - 1 > right.Count) { + m = left.Dequeue(); + right.Enqueue(m, -m); + } + } + + public double FindMedian() => + odd ? left.Peek() : (left.Peek() + right.Peek()) / 2.0; +} + +/** + * Your MedianFinder object will be instantiated and called as such: + * MedianFinder obj = new MedianFinder(); + * obj.AddNum(num); + * double param_2 = obj.FindMedian(); +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/readme.md b/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/readme.md new file mode 100644 index 0000000..7450c28 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/readme.md @@ -0,0 +1,79 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 300\. Longest Increasing Subsequence + +Medium + +Given an integer array `nums`, return the length of the longest strictly increasing subsequence. + +A **subsequence** is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, `[3,6,2,7]` is a subsequence of the array `[0,3,1,6,2,2,7]`. + +**Example 1:** + +**Input:** nums = [10,9,2,5,3,7,101,18] + +**Output:** 4 + +**Explanation:** The longest increasing subsequence is [2,3,7,101], therefore the length is 4. + +**Example 2:** + +**Input:** nums = [0,1,0,3,2,3] + +**Output:** 4 + +**Example 3:** + +**Input:** nums = [7,7,7,7,7,7,7] + +**Output:** 1 + +**Constraints:** + +* `1 <= nums.length <= 2500` +* -104 <= nums[i] <= 104 + +**Follow up:** Can you come up with an algorithm that runs in `O(n log(n))` time complexity? + +## Solution + +```csharp +public class Solution { + public int LengthOfLIS(int[] nums) { + if (nums == null || nums.Length == 0) { + return 0; + } + int[] dp = new int[nums.Length + 1]; + // prefill the dp table + for (int i = 1; i < dp.Length; i++) { + dp[i] = int.MaxValue; + } + int left = 1; + int right = 1; + foreach (int curr in nums) { + int start = left; + int end = right; + // binary search, find the one that is lower than curr + while (start + 1 < end) { + int mid = start + (end - start) / 2; + if (dp[mid] > curr) { + end = mid; + } else { + start = mid; + } + } + // update our dp table + if (dp[start] > curr) { + dp[start] = curr; + } else if (curr > dp[start] && curr < dp[end]) { + dp[end] = curr; + } else if (curr > dp[end]) { + dp[++end] = curr; + right++; + } + } + return right; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0322_coin_change/readme.md b/LeetCodeNet/G0301_0400/S0322_coin_change/readme.md new file mode 100644 index 0000000..8d1b576 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0322_coin_change/readme.md @@ -0,0 +1,62 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 322\. Coin Change + +Medium + +You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money. + +Return _the fewest number of coins that you need to make up that amount_. If that amount of money cannot be made up by any combination of the coins, return `-1`. + +You may assume that you have an infinite number of each kind of coin. + +**Example 1:** + +**Input:** coins = [1,2,5], amount = 11 + +**Output:** 3 + +**Explanation:** 11 = 5 + 5 + 1 + +**Example 2:** + +**Input:** coins = [2], amount = 3 + +**Output:** -1 + +**Example 3:** + +**Input:** coins = [1], amount = 0 + +**Output:** 0 + +**Constraints:** + +* `1 <= coins.length <= 12` +* 1 <= coins[i] <= 231 - 1 +* 0 <= amount <= 104 + +## Solution + +```csharp +public class Solution { + public int CoinChange(int[] coins, int amount) { + int[] dp = new int[amount + 1]; + dp[0] = 1; + foreach (int coin in coins) { + for (int i = coin; i <= amount; i++) { + int prev = dp[i - coin]; + if (prev > 0) { + if (dp[i] == 0) { + dp[i] = prev + 1; + } else { + dp[i] = Math.Min(dp[i], prev + 1); + } + } + } + } + return dp[amount] - 1; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0338_counting_bits/readme.md b/LeetCodeNet/G0301_0400/S0338_counting_bits/readme.md new file mode 100644 index 0000000..0668ec1 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0338_counting_bits/readme.md @@ -0,0 +1,67 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 338\. Counting Bits + +Easy + +Given an integer `n`, return _an array_ `ans` _of length_ `n + 1` _such that for each_ `i` (`0 <= i <= n`)_,_ `ans[i]` _is the **number of**_ `1`_**'s** in the binary representation of_ `i`. + +**Example 1:** + +**Input:** n = 2 + +**Output:** [0,1,1] + +**Explanation:** + + 0 --> 0 + 1 --> 1 + 2 --> 10 + +**Example 2:** + +**Input:** n = 5 + +**Output:** [0,1,1,2,1,2] + +**Explanation:** + + 0 --> 0 + 1 --> 1 + 2 --> 10 + 3 --> 11 + 4 --> 100 + 5 --> 101 + +**Constraints:** + +* 0 <= n <= 105 + +**Follow up:** + +* It is very easy to come up with a solution with a runtime of `O(n log n)`. Can you do it in linear time `O(n)` and possibly in a single pass? +* Can you do it without using any built-in function (i.e., like `__builtin_popcount` in C++)? + +## Solution + +```csharp +public class Solution { + public int[] CountBits(int num) { + int[] result = new int[num + 1]; + int borderPos = 1; + int incrPos = 1; + for (int i = 1; i < result.Length; i++) { + // when we reach pow of 2 , reset borderPos and incrPos + if (incrPos == borderPos) { + result[i] = 1; + incrPos = 1; + borderPos = i; + } else { + result[i] = 1 + result[incrPos++]; + } + } + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/readme.md b/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/readme.md new file mode 100644 index 0000000..ed2bc81 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/readme.md @@ -0,0 +1,63 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 347\. Top K Frequent Elements + +Medium + +Given an integer array `nums` and an integer `k`, return _the_ `k` _most frequent elements_. You may return the answer in **any order**. + +**Example 1:** + +**Input:** nums = [1,1,1,2,2,3], k = 2 + +**Output:** [1,2] + +**Example 2:** + +**Input:** nums = [1], k = 1 + +**Output:** [1] + +**Constraints:** + +* 1 <= nums.length <= 105 +* `k` is in the range `[1, the number of unique elements in the array]`. +* It is **guaranteed** that the answer is **unique**. + +**Follow up:** Your algorithm's time complexity must be better than `O(n log n)`, where n is the array's size. + +## Solution + +```csharp +using System; +using System.Collections.Generic; +using System.Linq; + +public class Solution { + public int[] TopKFrequent(int[] nums, int k) { + if (k == nums.Length) { + return nums; + } + //1. build dictionary + Dictionary dict = new Dictionary(); + for(int i=0; i < nums.Length; i++) { + if (!dict.ContainsKey(nums[i])) { + dict.Add(nums[i],0); + } + dict[nums[i]] +=1; + } + //2. build priority queue based on highest to lowest frequency + PriorityQueue pq = new PriorityQueue(Comparer.Create((x, y) => y.CompareTo(x))); + foreach (var key in dict.Keys) { + pq.Enqueue(key, dict[key]); + } + // 3. return top k elements from Priority Queue + var result = new int[k]; + for (var i = 0; i < k; i++) { + result[i] = pq.Dequeue(); + } + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0394_decode_string/readme.md b/LeetCodeNet/G0301_0400/S0394_decode_string/readme.md new file mode 100644 index 0000000..264143e --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0394_decode_string/readme.md @@ -0,0 +1,79 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 394\. Decode String + +Medium + +Given an encoded string, return its decoded string. + +The encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. Note that `k` is guaranteed to be a positive integer. + +You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc. + +Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there won't be input like `3a` or `2[4]`. + +**Example 1:** + +**Input:** s = "3[a]2[bc]" + +**Output:** "aaabcbc" + +**Example 2:** + +**Input:** s = "3[a2[c]]" + +**Output:** "accaccacc" + +**Example 3:** + +**Input:** s = "2[abc]3[cd]ef" + +**Output:** "abcabccdcdcdef" + +**Example 4:** + +**Input:** s = "abc3[cd]xyz" + +**Output:** "abccdcdcdxyz" + +**Constraints:** + +* `1 <= s.length <= 30` +* `s` consists of lowercase English letters, digits, and square brackets `'[]'`. +* `s` is guaranteed to be **a valid** input. +* All the integers in `s` are in the range `[1, 300]`. + +## Solution + +```csharp +using System.Text; + +public class Solution { + private int i = 0; + + public string DecodeString(string s) { + int count = 0; + var sb = new StringBuilder(); + while (i < s.Length) { + char c = s[i]; + i++; + if (char.IsLetter(c)) { + sb.Append(c); + } else if (char.IsDigit(c)) { + count = count * 10 + (int) char.GetNumericValue(c); + } else if (c == ']') { + break; + } else if (c == '[') { + // sub problem + string repeat = DecodeString(s); + while (count > 0) { + sb.Append(repeat); + count--; + } + } + } + return sb.ToString(); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/readme.md b/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/readme.md new file mode 100644 index 0000000..7d602dd --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/readme.md @@ -0,0 +1,54 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 416\. Partition Equal Subset Sum + +Medium + +Given a **non-empty** array `nums` containing **only positive integers**, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. + +**Example 1:** + +**Input:** nums = [1,5,11,5] + +**Output:** true + +**Explanation:** The array can be partitioned as [1, 5, 5] and [11]. + +**Example 2:** + +**Input:** nums = [1,2,3,5] + +**Output:** false + +**Explanation:** The array cannot be partitioned into equal sum subsets. + +**Constraints:** + +* `1 <= nums.length <= 200` +* `1 <= nums[i] <= 100` + +## Solution + +```csharp +public class Solution { + public bool CanPartition(int[] nums) { + int sums = 0; + foreach (int num in nums) { + sums += num; + } + if (sums % 2 == 1) { + return false; + } + sums /= 2; + bool[] dp = new bool[sums + 1]; + dp[0] = true; + foreach (int num in nums) { + for (int sum = sums; sum >= num; sum--) { + dp[sum] = dp[sum] || dp[sum - num]; + } + } + return dp[sums]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0437_path_sum_iii/readme.md b/LeetCodeNet/G0401_0500/S0437_path_sum_iii/readme.md new file mode 100644 index 0000000..93e3f89 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0437_path_sum_iii/readme.md @@ -0,0 +1,78 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 437\. Path Sum III + +Medium + +Given the `root` of a binary tree and an integer `targetSum`, return _the number of paths where the sum of the values along the path equals_ `targetSum`. + +The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes). + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/04/09/pathsum3-1-tree.jpg) + +**Input:** root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8 + +**Output:** 3 + +**Explanation:** The paths that sum to 8 are shown. + +**Example 2:** + +**Input:** root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 + +**Output:** 3 + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 1000]`. +* -109 <= Node.val <= 109 +* `-1000 <= targetSum <= 1000` + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for a binary tree node. + * public class TreeNode { + * public int val; + * public TreeNode left; + * public TreeNode right; + * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +public class Solution { + private int count = 0; + + public int PathSum(TreeNode root, int targetSum) { + if (root == null) { + return 0; + } + Helper(root, targetSum, 0); + PathSum(root.left, targetSum); + PathSum(root.right, targetSum); + return count; + } + + public void Helper(TreeNode node, int targetSum, long currSum) { + currSum += (long) node.val; + if (targetSum == currSum) { + count++; + } + if (node.left != null) { + Helper(node.left, targetSum, currSum); + } + if (node.right != null) { + Helper(node.right, targetSum, currSum); + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/readme.md b/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/readme.md new file mode 100644 index 0000000..57d27b7 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/readme.md @@ -0,0 +1,79 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 438\. Find All Anagrams in a String + +Medium + +Given two strings `s` and `p`, return _an array of all the start indices of_ `p`_'s anagrams in_ `s`. You may return the answer in **any order**. + +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 = "cbaebabacd", p = "abc" + +**Output:** [0,6] + +**Explanation:** + + The substring with start index = 0 is "cba", which is an anagram of "abc". + The substring with start index = 6 is "bac", which is an anagram of "abc". + +**Example 2:** + +**Input:** s = "abab", p = "ab" + +**Output:** [0,1,2] + +**Explanation:** + + The substring with start index = 0 is "ab", which is an anagram of "ab". + The substring with start index = 1 is "ba", which is an anagram of "ab". + The substring with start index = 2 is "ab", which is an anagram of "ab". + +**Constraints:** + +* 1 <= s.length, p.length <= 3 * 104 +* `s` and `p` consist of lowercase English letters. + +## Solution + +```csharp +using System; +using System.Collections.Generic; + +public class Solution { + public IList FindAnagrams(string s, string p) { + int[] map = new int[26]; + for (int index = 0; index < p.Length; ++index) { + map[p[index] - 'a']++; + } + IList res = new List(); + int i = 0; + int j = 0; + while (i < s.Length) { + int idx = s[i] - 'a'; + // add the new character + map[idx]--; + // if the length is greater than windows length, pop the left charcater in the window + if (i >= p.Length) { + map[s[j++] - 'a']++; + } + bool finish = true; + for (int k = 0; k < 26; k++) { + // if it is not an anagram of string p + if (map[k] != 0) { + finish = false; + break; + } + } + if (i >= p.Length - 1 && finish) { + res.Add(j); + } + i++; + } + return res; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0494_target_sum/readme.md b/LeetCodeNet/G0401_0500/S0494_target_sum/readme.md new file mode 100644 index 0000000..f7499b5 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0494_target_sum/readme.md @@ -0,0 +1,85 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 494\. Target Sum + +Medium + +You are given an integer array `nums` and an integer `target`. + +You want to build an **expression** out of nums by adding one of the symbols `'+'` and `'-'` before each integer in nums and then concatenate all the integers. + +* For example, if `nums = [2, 1]`, you can add a `'+'` before `2` and a `'-'` before `1` and concatenate them to build the expression `"+2-1"`. + +Return the number of different **expressions** that you can build, which evaluates to `target`. + +**Example 1:** + +**Input:** nums = [1,1,1,1,1], target = 3 + +**Output:** 5 + +**Explanation:** + + There are 5 ways to assign symbols to make the sum of nums be target 3. + -1 + 1 + 1 + 1 + 1 = 3 + +1 - 1 + 1 + 1 + 1 = 3 + +1 + 1 - 1 + 1 + 1 = 3 + +1 + 1 + 1 - 1 + 1 = 3 + +1 + 1 + 1 + 1 - 1 = 3 + +**Example 2:** + +**Input:** nums = [1], target = 1 + +**Output:** 1 + +**Constraints:** + +* `1 <= nums.length <= 20` +* `0 <= nums[i] <= 1000` +* `0 <= sum(nums[i]) <= 1000` +* `-1000 <= target <= 1000` + +## Solution + +```csharp +using System; +using System.Collections.Generic; + +public class Solution { + public int FindTargetSumWays(int[] nums, int s) { + int sum = 0; + s = Math.Abs(s); + foreach (int num in nums) { + sum += num; + } + // Invalid s, just return 0 + if (s > sum || (sum + s) % 2 != 0) { + return 0; + } + int[][] dp = new int[(sum + s) / 2 + 1][]; + for (int i = 0; i < dp.Length; i++) { + dp[i] = new int[nums.Length + 1]; + } + dp[0][0] = 1; + // empty knapsack must be processed specially + for (int i = 0; i < nums.Length; i++) { + if (nums[i] == 0) { + dp[0][i + 1] = dp[0][i] * 2; + } else { + dp[0][i + 1] = dp[0][i]; + } + } + for (int i = 1; i < dp.Length; i++) { + for (int j = 0; j < nums.Length; j++) { + dp[i][j + 1] += dp[i][j]; + if (nums[j] <= i) { + dp[i][j + 1] += dp[i - nums[j]][j]; + } + } + } + return dp[(sum + s) / 2][nums.Length]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/readme.md b/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/readme.md new file mode 100644 index 0000000..41e0038 --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/readme.md @@ -0,0 +1,59 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 543\. Diameter of Binary Tree + +Easy + +Given the `root` of a binary tree, return _the length of the **diameter** of the tree_. + +The **diameter** of a binary tree is the **length** of the longest path between any two nodes in a tree. This path may or may not pass through the `root`. + +The **length** of a path between two nodes is represented by the number of edges between them. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/06/diamtree.jpg) + +**Input:** root = [1,2,3,4,5] + +**Output:** 3 + +**Explanation:** 3 is the length of the path [4,2,1,3] or [5,2,1,3]. + +**Example 2:** + +**Input:** root = [1,2] + +**Output:** 1 + +**Constraints:** + +* The number of nodes in the tree is in the range [1, 104]. +* `-100 <= Node.val <= 100` + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + private int diameter; + + public int DiameterOfBinaryTree(TreeNode root) { + diameter = 0; + DiameterOfBinaryTreeUtil(root); + return diameter; + } + + private int DiameterOfBinaryTreeUtil(TreeNode root) { + if (root == null) { + return 0; + } + int leftLength = root.left != null ? 1 + DiameterOfBinaryTreeUtil(root.left) : 0; + int rightLength = root.right != null ? 1 + DiameterOfBinaryTreeUtil(root.right) : 0; + diameter = Math.Max(diameter, leftLength + rightLength); + return Math.Max(leftLength, rightLength); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/readme.md b/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/readme.md new file mode 100644 index 0000000..f465753 --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/readme.md @@ -0,0 +1,53 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 560\. Subarray Sum Equals K + +Medium + +Given an array of integers `nums` and an integer `k`, return _the total number of continuous subarrays whose sum equals to `k`_. + +**Example 1:** + +**Input:** nums = [1,1,1], k = 2 + +**Output:** 2 + +**Example 2:** + +**Input:** nums = [1,2,3], k = 3 + +**Output:** 2 + +**Constraints:** + +* 1 <= nums.length <= 2 * 104 +* `-1000 <= nums[i] <= 1000` +* -107 <= k <= 107 + +## Solution + +```csharp +using System.Collections.Generic; + +public class Solution { + public int SubarraySum(int[] nums, int k) { + int tempSum = 0; + int ret = 0; + Dictionary sumCount = new Dictionary(); + sumCount[0] = 1; + foreach (int i in nums) { + tempSum += i; + if (sumCount.ContainsKey(tempSum - k)) { + ret += sumCount[tempSum - k]; + } + if (sumCount.ContainsKey(tempSum)) { + sumCount[tempSum] = sumCount[tempSum] + 1; + } else { + sumCount[tempSum] = 1; + } + } + return ret; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/readme.md b/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/readme.md new file mode 100644 index 0000000..2bc7987 --- /dev/null +++ b/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/readme.md @@ -0,0 +1,61 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 647\. Palindromic Substrings + +Medium + +Given a string `s`, return _the number of **palindromic substrings** in it_. + +A string is a **palindrome** when it reads the same backward as forward. + +A **substring** is a contiguous sequence of characters within the string. + +**Example 1:** + +**Input:** s = "abc" + +**Output:** 3 + +**Explanation:** Three palindromic strings: "a", "b", "c". + +**Example 2:** + +**Input:** s = "aaa" + +**Output:** 6 + +**Explanation:** Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa". + +**Constraints:** + +* `1 <= s.length <= 1000` +* `s` consists of lowercase English letters. + +## Solution + +```csharp +public class Solution { + private void Expand(char[] a, int l, int r, int[] res) { + while (l >= 0 && r < a.Length) { + if (a[l] != a[r]) { + return; + } else { + res[0]++; + l--; + r++; + } + } + } + + public int CountSubstrings(string s) { + char[] a = s.ToCharArray(); + int[] res = {0}; + for (int i = 0; i < a.Length; i++) { + Expand(a, i, i, res); + Expand(a, i, i + 1, res); + } + return res[0]; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0701_0800/S0739_daily_temperatures/readme.md b/LeetCodeNet/G0701_0800/S0739_daily_temperatures/readme.md new file mode 100644 index 0000000..e9f26dc --- /dev/null +++ b/LeetCodeNet/G0701_0800/S0739_daily_temperatures/readme.md @@ -0,0 +1,57 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 739\. Daily Temperatures + +Medium + +Given an array of integers `temperatures` represents the daily temperatures, return _an array_ `answer` _such that_ `answer[i]` _is the number of days you have to wait after the_ ith _day to get a warmer temperature_. If there is no future day for which this is possible, keep `answer[i] == 0` instead. + +**Example 1:** + +**Input:** temperatures = [73,74,75,71,69,72,76,73] + +**Output:** [1,1,4,2,1,1,0,0] + +**Example 2:** + +**Input:** temperatures = [30,40,50,60] + +**Output:** [1,1,1,0] + +**Example 3:** + +**Input:** temperatures = [30,60,90] + +**Output:** [1,1,0] + +**Constraints:** + +* 1 <= temperatures.length <= 105 +* `30 <= temperatures[i] <= 100` + +## Solution + +```csharp +public class Solution { + public int[] DailyTemperatures(int[] temperatures) { + int[] sol = new int[temperatures.Length]; + sol[temperatures.Length - 1] = 0; + for (int i = sol.Length - 2; i >= 0; i--) { + int j = i + 1; + while (j <= sol.Length) { + if (temperatures[i] < temperatures[j]) { + sol[i] = j - i; + break; + } else { + if (sol[j] == 0) { + break; + } + j = j + sol[j]; + } + } + } + return sol; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0701_0800/S0763_partition_labels/readme.md b/LeetCodeNet/G0701_0800/S0763_partition_labels/readme.md new file mode 100644 index 0000000..9819355 --- /dev/null +++ b/LeetCodeNet/G0701_0800/S0763_partition_labels/readme.md @@ -0,0 +1,64 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 763\. Partition Labels + +Medium + +You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. + +Return _a list of integers representing the size of these parts_. + +**Example 1:** + +**Input:** s = "ababcbacadefegdehijhklij" + +**Output:** [9,7,8] + +**Explanation:** + + The partition is "ababcbaca", "defegde", "hijhklij". + This is a partition so that each letter appears in at most one part. + A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts. + +**Example 2:** + +**Input:** s = "eccbbbbdec" + +**Output:** [10] + +**Constraints:** + +* `1 <= s.length <= 500` +* `s` consists of lowercase English letters. + +## Solution + +```csharp +using System.Collections.Generic; + +public class Solution { + public IList PartitionLabels(string s) { + char[] letters = s.ToCharArray(); + IList result = new List(); + int[] position = new int[26]; + for (int index = 0; index < letters.Length; index++) { + position[letters[index] - 'a'] = index; + } + int i = 0; + int prev = -1; + int max = 0; + while (i < letters.Length) { + if (position[letters[i] - 'a'] > max) { + max = position[letters[i] - 'a']; + } + if (i == max) { + result.Add(i - prev); + prev = i; + } + i++; + } + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/readme.md b/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/readme.md new file mode 100644 index 0000000..d44259a --- /dev/null +++ b/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/readme.md @@ -0,0 +1,65 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 1143\. Longest Common Subsequence + +Medium + +Given two strings `text1` and `text2`, return _the length of their longest **common subsequence**._ If there is no **common subsequence**, return `0`. + +A **subsequence** of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. + +* For example, `"ace"` is a subsequence of `"abcde"`. + +A **common subsequence** of two strings is a subsequence that is common to both strings. + +**Example 1:** + +**Input:** text1 = "abcde", text2 = "ace" + +**Output:** 3 + +**Explanation:** The longest common subsequence is "ace" and its length is 3. + +**Example 2:** + +**Input:** text1 = "abc", text2 = "abc" + +**Output:** 3 + +**Explanation:** The longest common subsequence is "abc" and its length is 3. + +**Example 3:** + +**Input:** text1 = "abc", text2 = "def" + +**Output:** 0 + +**Explanation:** There is no such common subsequence, so the result is 0. + +**Constraints:** + +* `1 <= text1.length, text2.length <= 1000` +* `text1` and `text2` consist of only lowercase English characters. + +## Solution + +```csharp +public class Solution { + public int LongestCommonSubsequence(string text1, string text2) { + int n = text1.Length; + int m = text2.Length; + int[,] dp = new int[n + 1, m + 1]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (text1[i - 1] == text2[j - 1]) { + dp[i, j] = dp[i - 1, j - 1] + 1; + } else { + dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j - 1]); + } + } + } + return dp[n, m]; + } +} +``` \ No newline at end of file diff --git a/README.md b/README.md index c8f0c82..53283cd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) > ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews) -* [Binary Search I](#binary-search-i) * [Binary Search II](#binary-search-ii) * [Dynamic Programming I](#dynamic-programming-i) * [Programming Skills I](#programming-skills-i) @@ -16,71 +15,7 @@ * [Data Structure II](#data-structure-ii) * [Algorithm I](#algorithm-i) * [Algorithm II](#algorithm-ii) - -### Binary Search I - -#### Day 1 - -| | | | | | -|-|-|-|-|-|- - -#### Day 2 - -| | | | | | -|-|-|-|-|-|- -| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 - -#### Day 3 - -| | | | | | -|-|-|-|-|-|- - -#### Day 4 - -| | | | | | -|-|-|-|-|-|- - -#### Day 5 - -| | | | | | -|-|-|-|-|-|- -| 0034 |[Find First and Last Position of Element in Sorted Array](LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 171 | 5.87 - -#### Day 6 - -| | | | | | -|-|-|-|-|-|- - -#### Day 7 - -| | | | | | -|-|-|-|-|-|- - -#### Day 8 - -| | | | | | -|-|-|-|-|-|- - -#### Day 9 - -| | | | | | -|-|-|-|-|-|- - -#### Day 10 - -| | | | | | -|-|-|-|-|-|- - -#### Day 11 - -| | | | | | -|-|-|-|-|-|- -| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 - -#### Day 12 - -| | | | | | -|-|-|-|-|-|- +* [Binary Search I](#binary-search-i) ### Binary Search II @@ -98,6 +33,7 @@ | | | | | | |-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 #### Day 4 @@ -108,6 +44,7 @@ | | | | | | |-|-|-|-|-|- +| 0287 |[Find the Duplicate Number](LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 257 | 30.11 #### Day 6 @@ -123,6 +60,7 @@ | | | | | | |-|-|-|-|-|- +| 0240 |[Search a 2D Matrix II](LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 142 | 60.76 #### Day 9 @@ -195,6 +133,7 @@ | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 #### Day 3 @@ -205,12 +144,14 @@ | | | | | | |-|-|-|-|-|- +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 189 | 38.02 | 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 #### Day 5 | | | | | | |-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 276 | 20.05 #### Day 6 @@ -242,6 +183,7 @@ | | | | | | |-|-|-|-|-|- +| 0096 |[Unique Binary Search Trees](LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 13 | 98.48 #### Day 12 @@ -262,11 +204,13 @@ | | | | | | |-|-|-|-|-|- +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 16 | 93.42 #### Day 16 | | | | | | |-|-|-|-|-|- +| 0064 |[Minimum Path Sum](LeetCodeNet/G0001_0100/S0064_minimum_path_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 74 | 94.37 #### Day 17 @@ -278,16 +222,20 @@ | | | | | | |-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 #### Day 19 | | | | | | |-|-|-|-|-|- +| 1143 |[Longest Common Subsequence](LeetCodeNet/G1101_1200/S1143_longest_common_subsequence)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 59 | 90.45 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 #### Day 20 | | | | | | |-|-|-|-|-|- +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 #### Day 21 @@ -325,6 +273,7 @@ | | | | | | |-|-|-|-|-|- +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 #### Day 7 Array @@ -387,11 +336,13 @@ | | | | | | |-|-|-|-|-|- +| 0739 |[Daily Temperatures](LeetCodeNet/G0701_0800/S0739_daily_temperatures)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 376 | 44.29 #### Day 7 | | | | | | |-|-|-|-|-|- +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 92 | 97.78 #### Day 8 @@ -412,11 +363,13 @@ | | | | | | |-|-|-|-|-|- +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 145 | 96.20 #### Day 12 | | | | | | |-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 103 | 97.89 #### Day 13 @@ -625,6 +578,7 @@ | | | | | | |-|-|-|-|-|- +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 75 | 97.31 #### Day 9 Graph/BFS/DFS @@ -635,16 +589,19 @@ | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 #### Day 11 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 16 | 93.42 #### Day 12 Sliding Window/Two Pointer | | | | | | |-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 103 | 97.89 #### Day 13 Hashmap @@ -656,6 +613,7 @@ | | | | | | |-|-|-|-|-|- +| 0394 |[Decode String](LeetCodeNet/G0301_0400/S0394_decode_string)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 44 | 99.55 #### Day 15 Heap @@ -699,11 +657,14 @@ | | | | | | |-|-|-|-|-|- +| 0543 |[Diameter of Binary Tree](LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 74 | 84.67 +| 0437 |[Path Sum III](LeetCodeNet/G0401_0500/S0437_path_sum_iii)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 76 | 97.16 #### Day 8 Binary Search | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 | 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 #### Day 9 Binary Search Tree @@ -725,22 +686,26 @@ | | | | | | |-|-|-|-|-|- +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 #### Day 13 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0416 |[Partition Equal Subset Sum](LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 95 | 97.38 #### Day 14 Sliding Window/Two Pointer | | | | | | |-|-|-|-|-|- | 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 +| 0076 |[Minimum Window Substring](LeetCodeNet/G0001_0100/S0076_minimum_window_substring)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 56 | 98.72 #### Day 15 Tree | | | | | | |-|-|-|-|-|- +| 0101 |[Symmetric Tree](LeetCodeNet/G0101_0200/S0101_symmetric_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 64 | 97.79 #### Day 16 Design @@ -751,6 +716,7 @@ | | | | | | |-|-|-|-|-|- +| 0056 |[Merge Intervals](LeetCodeNet/G0001_0100/S0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 149 | 89.48 #### Day 18 Stack @@ -785,6 +751,8 @@ | 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 | 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 96.68 | 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 +| 0394 |[Decode String](LeetCodeNet/G0301_0400/S0394_decode_string)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 44 | 99.55 +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 145 | 96.20 #### Udemy Binary Search @@ -796,8 +764,12 @@ | | | | | | |-|-|-|-|-|- +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 | 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 189 | 38.02 +| 0075 |[Sort Colors](LeetCodeNet/G0001_0100/S0075_sort_colors)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 98 | 93.59 | 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 192 | 13.98 +| 0239 |[Sliding Window Maximum](LeetCodeNet/G0201_0300/S0239_sliding_window_maximum)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Big_O_Time_O(n\*k)_Space_O(n+k) | 493 | 46.05 #### Udemy Two Pointers @@ -810,6 +782,7 @@ | | | | | | |-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 276 | 20.05 #### Udemy Sorting Algorithms @@ -820,6 +793,10 @@ | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 92 | 97.78 +| 0073 |[Set Matrix Zeroes](LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 124 | 96.92 +| 0056 |[Merge Intervals](LeetCodeNet/G0001_0100/S0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 149 | 89.48 #### Udemy Linked List @@ -833,6 +810,9 @@ | | | | | | |-|-|-|-|-|- +| 0094 |[Binary Tree Inorder Traversal](LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 90 | 99.30 +| 0543 |[Diameter of Binary Tree](LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 74 | 84.67 +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 75 | 97.31 #### Udemy Trie and Heap @@ -848,6 +828,11 @@ | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 +| 0064 |[Minimum Path Sum](LeetCodeNet/G0001_0100/S0064_minimum_path_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 74 | 94.37 +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 +| 1143 |[Longest Common Subsequence](LeetCodeNet/G1101_1200/S1143_longest_common_subsequence)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 59 | 90.45 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 | 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 59 | 96.10 #### Udemy Backtracking/Recursion @@ -856,6 +841,7 @@ |-|-|-|-|-|- | 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 | 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 +| 0078 |[Subsets](LeetCodeNet/G0001_0100/S0078_subsets)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 101 | 94.29 | 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 108 | 95.24 | 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 @@ -863,6 +849,7 @@ | | | | | | |-|-|-|-|-|- +| 0338 |[Counting Bits](LeetCodeNet/G0301_0400/S0338_counting_bits)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 67 | 98.82 #### Udemy Design @@ -875,6 +862,7 @@ | | | | | | |-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 276 | 20.05 #### Day 2 Array @@ -896,6 +884,7 @@ | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 #### Day 6 String @@ -923,11 +912,13 @@ | | | | | | |-|-|-|-|-|- +| 0094 |[Binary Tree Inorder Traversal](LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 90 | 99.30 #### Day 11 Tree | | | | | | |-|-|-|-|-|- +| 0101 |[Symmetric Tree](LeetCodeNet/G0101_0200/S0101_symmetric_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 64 | 97.79 #### Day 12 Tree @@ -943,6 +934,7 @@ | | | | | | |-|-|-|-|-|- +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 75 | 97.31 ### Data Structure II @@ -956,21 +948,26 @@ | | | | | | |-|-|-|-|-|- +| 0075 |[Sort Colors](LeetCodeNet/G0001_0100/S0075_sort_colors)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 98 | 93.59 +| 0056 |[Merge Intervals](LeetCodeNet/G0001_0100/S0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 149 | 89.48 #### Day 3 Array | | | | | | |-|-|-|-|-|- +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 92 | 97.78 #### Day 4 Array | | | | | | |-|-|-|-|-|- +| 0240 |[Search a 2D Matrix II](LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 142 | 60.76 #### Day 5 Array | | | | | | |-|-|-|-|-|- +| 0560 |[Subarray Sum Equals K](LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 135 | 46.56 #### Day 6 String @@ -981,11 +978,13 @@ | | | | | | |-|-|-|-|-|- +| 0763 |[Partition Labels](LeetCodeNet/G0701_0800/S0763_partition_labels)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 82 | 98.72 #### Day 8 String | | | | | | |-|-|-|-|-|- +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 145 | 96.20 #### Day 9 String @@ -1050,6 +1049,7 @@ | | | | | | |-|-|-|-|-|- +| 0347 |[Top K Frequent Elements](LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Big_O_Time_O(n\*log(n))_Space_O(k) | 125 | 95.29 #### Day 21 Heap Priority Queue @@ -1073,6 +1073,7 @@ | | | | | | |-|-|-|-|-|- +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 #### Day 4 Two Pointers @@ -1122,6 +1123,7 @@ | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 #### Day 13 Bit Manipulation @@ -1141,6 +1143,7 @@ |-|-|-|-|-|- | 0034 |[Find First and Last Position of Element in Sorted Array](LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 171 | 5.87 | 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 #### Day 2 Binary Search @@ -1163,6 +1166,7 @@ | | | | | | |-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 103 | 97.89 #### Day 6 Breadth First Search Depth First Search @@ -1183,6 +1187,7 @@ | | | | | | |-|-|-|-|-|- +| 0078 |[Subsets](LeetCodeNet/G0001_0100/S0078_subsets)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 101 | 94.29 #### Day 10 Recursion Backtracking @@ -1196,17 +1201,20 @@ |-|-|-|-|-|- | 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 108 | 95.24 | 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 +| 0079 |[Word Search](LeetCodeNet/G0001_0100/S0079_word_search)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 152 | 99.69 #### Day 12 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 189 | 38.02 #### Day 13 Dynamic Programming | | | | | | |-|-|-|-|-|- | 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 16 | 93.42 #### Day 14 Dynamic Programming @@ -1223,16 +1231,20 @@ | | | | | | |-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 #### Day 17 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 1143 |[Longest Common Subsequence](LeetCodeNet/G1101_1200/S1143_longest_common_subsequence)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 59 | 90.45 #### Day 18 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 #### Day 19 Bit Manipulation @@ -1249,10 +1261,117 @@ | | | | | | |-|-|-|-|-|- +### Binary Search I + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- +| 0034 |[Find First and Last Position of Element in Sorted Array](LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 171 | 5.87 + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- + ## Algorithms | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|-------- +| 1143 |[Longest Common Subsequence](LeetCodeNet/G1101_1200/S1143_longest_common_subsequence)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_17_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 59 | 90.45 +| 0763 |[Partition Labels](LeetCodeNet/G0701_0800/S0763_partition_labels)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Data_Structure_II_Day_7_String, Big_O_Time_O(n)_Space_O(1) | 82 | 98.72 +| 0739 |[Daily Temperatures](LeetCodeNet/G0701_0800/S0739_daily_temperatures)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Programming_Skills_II_Day_6, Big_O_Time_O(n)_Space_O(n) | 376 | 44.29 +| 0647 |[Palindromic Substrings](LeetCodeNet/G0601_0700/S0647_palindromic_substrings)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n) | 48 | 92.55 +| 0560 |[Subarray Sum Equals K](LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Data_Structure_II_Day_5_Array, Big_O_Time_O(n)_Space_O(n) | 135 | 46.56 +| 0543 |[Diameter of Binary Tree](LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 74 | 84.67 +| 0494 |[Target Sum](LeetCodeNet/G0401_0500/S0494_target_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Backtracking, Big_O_Time_O(n\*(sum+s))_Space_O(n\*(sum+s)) | 62 | 99.32 +| 0438 |[Find All Anagrams in a String](LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Programming_Skills_II_Day_12, Level_1_Day_12_Sliding_Window/Two_Pointer, Big_O_Time_O(n+m)_Space_O(1) | 103 | 97.89 +| 0437 |[Path Sum III](LeetCodeNet/G0401_0500/S0437_path_sum_iii)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 76 | 97.16 +| 0416 |[Partition Equal Subset Sum](LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 95 | 97.38 +| 0394 |[Decode String](LeetCodeNet/G0301_0400/S0394_decode_string)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Level_1_Day_14_Stack, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 44 | 99.55 +| 0347 |[Top K Frequent Elements](LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Data_Structure_II_Day_20_Heap_Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(k) | 125 | 95.29 +| 0338 |[Counting Bits](LeetCodeNet/G0301_0400/S0338_counting_bits)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation, Udemy_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 67 | 98.82 +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Algorithm_II_Day_16_Dynamic_Programming, Binary_Search_II_Day_3, Dynamic_Programming_I_Day_18, Udemy_Dynamic_Programming, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 +| 0295 |[Find Median from Data Stream](LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Big_O_Time_O(n\*log_n)_Space_O(n) | 642 | 21.62 +| 0287 |[Find the Duplicate Number](LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Binary_Search_II_Day_5, Big_O_Time_O(n)_Space_O(n) | 257 | 30.11 +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Programming_Skills_I_Day_6_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 +| 0240 |[Search a 2D Matrix II](LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Data_Structure_II_Day_4_Array, Binary_Search_II_Day_8, Big_O_Time_O(n+m)_Space_O(1) | 142 | 60.76 +| 0239 |[Sliding Window Maximum](LeetCodeNet/G0201_0300/S0239_sliding_window_maximum)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Udemy_Arrays, Big_O_Time_O(n\*k)_Space_O(n+k) | 493 | 46.05 +| 0101 |[Symmetric Tree](LeetCodeNet/G0101_0200/S0101_symmetric_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_11_Tree, Level_2_Day_15_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 64 | 97.79 +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_I_Day_14_Tree, Level_1_Day_8_Binary_Search_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(N)_Space_O(log(N)) | 75 | 97.31 +| 0096 |[Unique Binary Search Trees](LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 13 | 98.48 +| 0094 |[Binary Tree Inorder Traversal](LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Data_Structure_I_Day_10_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 90 | 99.30 +| 0084 |[Largest Rectangle in Histogram](LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 304 | 30.92 +| 0079 |[Word Search](LeetCodeNet/G0001_0100/S0079_word_search)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 152 | 99.69 +| 0078 |[Subsets](LeetCodeNet/G0001_0100/S0078_subsets)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Algorithm_II_Day_9_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 101 | 94.29 +| 0076 |[Minimum Window Substring](LeetCodeNet/G0001_0100/S0076_minimum_window_substring)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Big_O_Time_O(s.length())_Space_O(1) | 56 | 98.72 +| 0075 |[Sort Colors](LeetCodeNet/G0001_0100/S0075_sort_colors)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 98 | 93.59 +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Data_Structure_I_Day_5_Array, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_8, Level_2_Day_8_Binary_Search, Udemy_2D_Arrays/Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 +| 0073 |[Set Matrix Zeroes](LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 124 | 96.92 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_2, Level_1_Day_10_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 +| 0064 |[Minimum Path Sum](LeetCodeNet/G0001_0100/S0064_minimum_path_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 74 | 94.37 +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_15, Level_1_Day_11_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 16 | 93.42 +| 0056 |[Merge Intervals](LeetCodeNet/G0001_0100/S0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Data_Structure_II_Day_2_Array, Level_2_Day_17_Interval, Udemy_2D_Arrays/Matrix, Big_O_Time_O(n_log_n)_Space_O(n) | 149 | 89.48 +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_4, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 189 | 38.02 +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Data_Structure_I_Day_1_Array, Dynamic_Programming_I_Day_5, Udemy_Famous_Algorithm, Big_O_Time_O(n)_Space_O(1) | 276 | 20.05 +| 0051 |[N-Queens](LeetCodeNet/G0001_0100/S0051_n_queens)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 106 | 96.34 +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Data_Structure_II_Day_8_String, Programming_Skills_II_Day_11, Udemy_Strings, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 145 | 96.20 +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Data_Structure_II_Day_3_Array, Programming_Skills_II_Day_7, Udemy_2D_Arrays/Matrix, Big_O_Time_O(n^2)_Space_O(1) | 92 | 97.78 | 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 | 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_4, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 | 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Dynamic_Programming_I_Day_9, Udemy_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96