diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml index 2a6ac34..075f359 100644 --- a/.github/workflows/dotnet-desktop.yml +++ b/.github/workflows/dotnet-desktop.yml @@ -8,24 +8,26 @@ on: jobs: build-windows: - runs-on: windows-2019 + runs-on: windows-latest steps: - - uses: actions/checkout@v3 - - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 6.0.x - - - name: Setup NuGet - uses: NuGet/setup-nuget@v1.2.0 - - - name: Restore dependencies - run: dotnet restore + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2.0.1 + + - name: Restore dependencies + run: dotnet restore - - name: Build - run: dotnet build --configuration Release + - name: Build + run: dotnet build --configuration Release - - name: Test - run: dotnet test --logger "trx;LogFileName=test-results.trx" || true + - name: Test + run: dotnet test --logger "trx;LogFileName=test-results.trx" || true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1062418 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +*.iml diff --git a/LICENSE b/LICENSE index 04ac570..5bebe5b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Valentyn Kolesnikov +Copyright (c) 2023-2024 Valentyn Kolesnikov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LeetCodeNet.Tests/Com_github_leetcode/TreeUtils.cs b/LeetCodeNet.Tests/Com_github_leetcode/TreeUtils.cs new file mode 100644 index 0000000..e51dbba --- /dev/null +++ b/LeetCodeNet.Tests/Com_github_leetcode/TreeUtils.cs @@ -0,0 +1,33 @@ +namespace LeetCodeNet.Com_github_leetcode { + +public class TreeUtils { + /* + * This method is to construct a normal binary tree. The input reads like + * this for [5, 3, 6, 2, 4, null, null, 1], i.e. preorder: + 5 + / \ + 3 6 + / \ / \ + 2 4 # # + / + 1 + */ + public static TreeNode ConstructBinaryTree(List treeValues) { + TreeNode root = new TreeNode(treeValues[0]); + Queue queue = new Queue(); + queue.Enqueue(root); + for (int i = 1; i < treeValues.Count; i++) { + TreeNode curr = queue.Dequeue(); + if (treeValues[i] != null) { + curr.left = new TreeNode(treeValues[i]); + queue.Enqueue(curr.left); + } + if (++i < treeValues.Count && treeValues[i] != null) { + curr.right = new TreeNode(treeValues[i]); + queue.Enqueue(curr.right); + } + } + return root; + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0001_two_sum/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0001_two_sum/SolutionTest.cs index 7033041..5c2eeca 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0001_two_sum/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0001_two_sum/SolutionTest.cs @@ -1,5 +1,5 @@ namespace LeetCodeNet.G0001_0100.S0001_two_sum { -using System; + using Xunit; public class SolutionTest { diff --git a/LeetCodeNet.Tests/G0001_0100/S0003_longest_substring_without_repeating_characters/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0003_longest_substring_without_repeating_characters/SolutionTest.cs index 7247d6c..37f34b5 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0003_longest_substring_without_repeating_characters/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0003_longest_substring_without_repeating_characters/SolutionTest.cs @@ -1,7 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0003_longest_substring_without_repeating_characters { using Xunit; -using System; public class SolutionTest { [Fact] diff --git a/LeetCodeNet.Tests/G0001_0100/S0004_median_of_two_sorted_arrays/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0004_median_of_two_sorted_arrays/SolutionTest.cs index 3eab76d..9a68430 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0004_median_of_two_sorted_arrays/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0004_median_of_two_sorted_arrays/SolutionTest.cs @@ -1,7 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0004_median_of_two_sorted_arrays { using Xunit; -using System; public class SolutionTest { [Fact] diff --git a/LeetCodeNet.Tests/G0001_0100/S0005_longest_palindromic_substring/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0005_longest_palindromic_substring/SolutionTest.cs index 9fcf6a0..1ae09f7 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0005_longest_palindromic_substring/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0005_longest_palindromic_substring/SolutionTest.cs @@ -1,7 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0005_longest_palindromic_substring { using Xunit; -using System; public class SolutionTest { [Fact] diff --git a/LeetCodeNet.Tests/G0001_0100/S0006_zigzag_conversion/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0006_zigzag_conversion/SolutionTest.cs index e962cb8..68afef6 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0006_zigzag_conversion/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0006_zigzag_conversion/SolutionTest.cs @@ -1,7 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0006_zigzag_conversion { using Xunit; -using System; public class SolutionTest { [Fact] diff --git a/LeetCodeNet.Tests/G0001_0100/S0007_reverse_integer/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0007_reverse_integer/SolutionTest.cs index 46be561..0ddc091 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0007_reverse_integer/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0007_reverse_integer/SolutionTest.cs @@ -1,7 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0007_reverse_integer { using Xunit; -using System; public class SolutionTest { [Fact] diff --git a/LeetCodeNet.Tests/G0001_0100/S0008_string_to_integer_atoi/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0008_string_to_integer_atoi/SolutionTest.cs index 1682aa9..83ba567 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0008_string_to_integer_atoi/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0008_string_to_integer_atoi/SolutionTest.cs @@ -1,7 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0008_string_to_integer_atoi { using Xunit; -using System; public class SolutionTest { [Fact] diff --git a/LeetCodeNet.Tests/G0001_0100/S0009_palindrome_number/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0009_palindrome_number/SolutionTest.cs index 162ebe4..e707604 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0009_palindrome_number/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0009_palindrome_number/SolutionTest.cs @@ -1,22 +1,21 @@ namespace LeetCodeNet.G0001_0100.S0009_palindrome_number { using Xunit; -using System; public class SolutionTest { [Fact] public void IsPalindrome() { - Assert.Equal(true, new Solution().IsPalindrome(121)); + Assert.True(new Solution().IsPalindrome(121)); } [Fact] public void IsPalindrome2() { - Assert.Equal(false, new Solution().IsPalindrome(-121)); + Assert.False(new Solution().IsPalindrome(-121)); } [Fact] public void IsPalindrome3() { - Assert.Equal(false, new Solution().IsPalindrome(10)); + Assert.False(new Solution().IsPalindrome(10)); } } } diff --git a/LeetCodeNet.Tests/G0001_0100/S0010_regular_expression_matching/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0010_regular_expression_matching/SolutionTest.cs index 415adf0..ff961fd 100644 --- a/LeetCodeNet.Tests/G0001_0100/S0010_regular_expression_matching/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0001_0100/S0010_regular_expression_matching/SolutionTest.cs @@ -1,32 +1,31 @@ namespace LeetCodeNet.G0001_0100.S0010_regular_expression_matching { using Xunit; -using System; public class SolutionTest { [Fact] public void IsMatch() { - Assert.Equal(false, new Solution().IsMatch("aa", "a")); + Assert.False(new Solution().IsMatch("aa", "a")); } [Fact] public void IsMatch2() { - Assert.Equal(true, new Solution().IsMatch("aa", "a*")); + Assert.True(new Solution().IsMatch("aa", "a*")); } [Fact] public void IsMatch3() { - Assert.Equal(true, new Solution().IsMatch("ab", ".*")); + Assert.True(new Solution().IsMatch("ab", ".*")); } [Fact] public void IsMatch4() { - Assert.Equal(true, new Solution().IsMatch("aab", "c*a*b")); + Assert.True(new Solution().IsMatch("aab", "c*a*b")); } [Fact] public void IsMatch5() { - Assert.Equal(false, new Solution().IsMatch("mississippi", "mis*is*p*.")); + Assert.False(new Solution().IsMatch("mississippi", "mis*is*p*.")); } } } diff --git a/LeetCodeNet.Tests/G0001_0100/S0048_rotate_image/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0048_rotate_image/SolutionTest.cs new file mode 100644 index 0000000..3ded5bf --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0048_rotate_image/SolutionTest.cs @@ -0,0 +1,14 @@ +namespace LeetCodeNet.G0001_0100.S0048_rotate_image { + +using Xunit; + +public class SolutionTest { + [Fact] + public void Rotate() { + var input = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } }; + var exected = new int[][] { new int[] { 7, 4, 1 }, new int[] { 8, 5, 2 }, new int[] { 9, 6, 3 } }; + new Solution().Rotate(input); + Assert.Equal(exected, input); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0049_group_anagrams/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0049_group_anagrams/SolutionTest.cs new file mode 100644 index 0000000..b09a4cd --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0049_group_anagrams/SolutionTest.cs @@ -0,0 +1,25 @@ +namespace LeetCodeNet.G0001_0100.S0049_group_anagrams { + +using Xunit; + +public class SolutionTest { + [Fact] + public void GroupAnagrams() { + List> exected = new List> { new List { "eat", "tea", "ate" }, + new List { "tan", "nat" }, new List { "bat" } }; + Assert.Equal(exected, new Solution().GroupAnagrams(new string[] { "eat", "tea", "tan", "ate", "nat", "bat" })); + } + + [Fact] + public void GroupAnagrams2() { + List> exected = new List> { new List { "" } }; + Assert.Equal(exected, new Solution().GroupAnagrams(new string[] { "" })); + } + + [Fact] + public void GroupAnagrams3() { + List> exected = new List> { new List { "a" } }; + Assert.Equal(exected, new Solution().GroupAnagrams(new string[] { "a" })); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0051_n_queens/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0051_n_queens/SolutionTest.cs new file mode 100644 index 0000000..bc932d2 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0051_n_queens/SolutionTest.cs @@ -0,0 +1,19 @@ +namespace LeetCodeNet.G0001_0100.S0051_n_queens { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SolveNQueens() { + var exected = new List> { new List { "..Q.", "Q...", "...Q", ".Q.." }, + new List { ".Q..", "...Q", "Q...", "..Q." } }; + Assert.Equal(exected, new Solution().SolveNQueens(4)); + } + + [Fact] + public void SolveNQueens2() { + var exected = new List> { new List { "Q" } }; + Assert.Equal(exected, new Solution().SolveNQueens(1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0053_maximum_subarray/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0053_maximum_subarray/SolutionTest.cs new file mode 100644 index 0000000..5faf7f6 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0053_maximum_subarray/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0001_0100.S0053_maximum_subarray { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MaxSubArray() { + Assert.Equal(6, new Solution().MaxSubArray(new int[] { -2, 1, -3, 4, -1, 2, 1, -5, 4 })); + } + + [Fact] + public void MaxSubArray2() { + Assert.Equal(1, new Solution().MaxSubArray(new int[] { 1 })); + } + + [Fact] + public void MaxSubArray3() { + Assert.Equal(23, new Solution().MaxSubArray(new int[] { 5, 4, -1, 7, 8 })); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0055_jump_game/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0055_jump_game/SolutionTest.cs new file mode 100644 index 0000000..8a96fdf --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0055_jump_game/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0001_0100.S0055_jump_game { + +using Xunit; + +public class SolutionTest { + [Fact] + public void CanJump() { + Assert.True(new Solution().CanJump(new int[] { 2, 3, 1, 1, 4 })); + } + + [Fact] + public void CanJump2() { + Assert.False(new Solution().CanJump(new int[] { 3, 2, 1, 0, 4 })); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0056_merge_intervals/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0056_merge_intervals/SolutionTest.cs new file mode 100644 index 0000000..e4a9504 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0056_merge_intervals/SolutionTest.cs @@ -0,0 +1,20 @@ +namespace LeetCodeNet.G0001_0100.S0056_merge_intervals { + +using Xunit; + +public class SolutionTest { + [Fact] + public void Merge() { + var input = new int[][] { new int[] { 1, 3 }, new int[] { 2, 6 }, new int[] { 8, 10 }, new int[] { 15, 18 } }; + var expected = new int[][] { new int[] { 1, 6 }, new int[] { 8, 10 }, new int[] { 15, 18 } }; + Assert.Equal(expected, new Solution().Merge(input)); + } + + [Fact] + public void Merge2() { + var input = new int[][] { new int[] { 1, 4 }, new int[] { 4, 5 } }; + var expected = new int[][] { new int[] { 1, 5 } }; + Assert.Equal(expected, new Solution().Merge(input)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0062_unique_paths/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0062_unique_paths/SolutionTest.cs new file mode 100644 index 0000000..42dbca2 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0062_unique_paths/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0001_0100.S0062_unique_paths { + +using Xunit; + +public class SolutionTest { + [Fact] + public void UniquePaths() { + Assert.Equal(28, new Solution().UniquePaths(3, 7)); + } + + [Fact] + public void UniquePaths2() { + Assert.Equal(3, new Solution().UniquePaths(3, 2)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0064_minimum_path_sum/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0064_minimum_path_sum/SolutionTest.cs new file mode 100644 index 0000000..39f3e49 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0064_minimum_path_sum/SolutionTest.cs @@ -0,0 +1,18 @@ +namespace LeetCodeNet.G0001_0100.S0064_minimum_path_sum { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MinPathSum() { + var input = new int[][] { new int[] { 1, 3, 1 }, new int[] { 1, 5, 1 }, new int[] { 4, 2, 1 } }; + Assert.Equal(7, new Solution().MinPathSum(input)); + } + + [Fact] + public void MinPathSum2() { + var input = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } }; + Assert.Equal(12, new Solution().MinPathSum(input)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0070_climbing_stairs/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0070_climbing_stairs/SolutionTest.cs new file mode 100644 index 0000000..3323a2c --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0070_climbing_stairs/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0001_0100.S0070_climbing_stairs { + +using Xunit; + +public class SolutionTest { + [Fact] + public void ClimbStairs() { + Assert.Equal(2, new Solution().ClimbStairs(2)); + } + + [Fact] + public void ClimbStairs2() { + Assert.Equal(3, new Solution().ClimbStairs(3)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0072_edit_distance/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0072_edit_distance/SolutionTest.cs new file mode 100644 index 0000000..ee3b1da --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0072_edit_distance/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0001_0100.S0072_edit_distance { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MinDistance() { + Assert.Equal(3, new Solution().MinDistance("horse", "ros")); + } + + [Fact] + public void MinDistance2() { + Assert.Equal(5, new Solution().MinDistance("intention", "execution")); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0073_set_matrix_zeroes/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0073_set_matrix_zeroes/SolutionTest.cs new file mode 100644 index 0000000..978cdb2 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0073_set_matrix_zeroes/SolutionTest.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0001_0100.S0073_set_matrix_zeroes { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SetZeroes() { + var input = new int[][] { new int[] { 1, 1, 1 }, new int[] { 1, 0, 1 }, new int[] { 1, 1, 1 } }; + var output = new int[][] { new int[] { 1, 0, 1 }, new int[] { 0, 0, 0 }, new int[] { 1, 0, 1 } }; + new Solution().SetZeroes(input); + Assert.Equal(input, output); + } + + [Fact] + public void SetZeroes2() { + var input = new int[][] { new int[] { 0, 1, 2, 0 }, new int[] { 3, 4, 5, 2 }, new int[] { 1, 3, 1, 5 } }; + var output = new int[][] { new int[] { 0, 0, 0, 0 }, new int[] { 0, 4, 5, 0 }, new int[] { 0, 3, 1, 0 } }; + new Solution().SetZeroes(input); + Assert.Equal(input, output); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0074_search_a_2d_matrix/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0074_search_a_2d_matrix/SolutionTest.cs new file mode 100644 index 0000000..15911d4 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0074_search_a_2d_matrix/SolutionTest.cs @@ -0,0 +1,20 @@ +namespace LeetCodeNet.G0001_0100.S0074_search_a_2d_matrix { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SearchMatrix() { + var input = new int[][] { new int[] { 1, 3, 5, 7 }, new int[] { 10, 11, 16, 20 }, + new int[] { 23, 30, 34, 60 } }; + Assert.True(new Solution().SearchMatrix(input, 3)); + } + + [Fact] + public void SearchMatrix2() { + var input = new int[][] { new int[] { 1, 3, 5, 7 }, new int[] { 10, 11, 16, 20 }, + new int[] { 23, 30, 34, 60 } }; + Assert.False(new Solution().SearchMatrix(input, 13)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0075_sort_colors/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0075_sort_colors/SolutionTest.cs new file mode 100644 index 0000000..9e80fc9 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0075_sort_colors/SolutionTest.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0001_0100.S0075_sort_colors { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SortColors() { + var input = new int[] { 2, 0, 2, 1, 1, 0 }; + var output = new int[] { 0, 0, 1, 1, 2, 2 }; + new Solution().SortColors(input); + Assert.Equal(output, input); + } + + [Fact] + public void SortColors2() { + var input = new int[] { 2, 0, 2, 1, 1, 0 }; + var output = new int[] { 0, 0, 1, 1, 2, 2 }; + new Solution().SortColors(input); + Assert.Equal(output, input); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0076_minimum_window_substring/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0076_minimum_window_substring/SolutionTest.cs new file mode 100644 index 0000000..9c03ac3 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0076_minimum_window_substring/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0001_0100.S0076_minimum_window_substring { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MinWindow() { + Assert.Equal("BANC", new Solution().MinWindow("ADOBECODEBANC", "ABC")); + } + + [Fact] + public void MinWindow2() { + Assert.Equal("a", new Solution().MinWindow("a", "a")); + } + + [Fact] + public void MinWindow3() { + Assert.Equal("", new Solution().MinWindow("a", "aa")); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0078_subsets/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0078_subsets/SolutionTest.cs new file mode 100644 index 0000000..2f333b7 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0078_subsets/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0001_0100.S0078_subsets { + +using Xunit; +using System.Collections.Generic; +using System.Linq; + +public class SolutionTest { + [Fact] + public void Subsets() { + int[][] expected = new int[][] {new int[] {}, new int[] {1}, + new int[] {1, 2}, new int[] {1, 2, 3}, new int[] {1, 3}, new int[] {2}, new int[] {2, 3}, new int[] {3}}; + Assert.Equal(expected, new Solution().Subsets(new int[] {1, 2, 3}).Select(a => a.ToArray()).ToArray()); + } + + [Fact] + public void Subsets2() { + int[][] expected = new int[][] {new int[] {}, new int[] {0}}; + Assert.Equal(expected, new Solution().Subsets(new int[] {0}).Select(a => a.ToArray()).ToArray()); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0079_word_search/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0079_word_search/SolutionTest.cs new file mode 100644 index 0000000..d02af40 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0079_word_search/SolutionTest.cs @@ -0,0 +1,27 @@ +namespace LeetCodeNet.G0001_0100.S0079_word_search { + +using Xunit; + +public class SolutionTest { + [Fact] + public void Exist() { + var input = new char[][] { new char[] { 'A', 'B', 'C', 'E' }, + new char[] { 'S', 'F', 'C', 'S' }, new char[] { 'A', 'D', 'E', 'E' } }; + Assert.True(new Solution().Exist(input, "ABCCED")); + } + + [Fact] + public void Exist2() { + var input = new char[][] { new char[] { 'A', 'B', 'C', 'E' }, + new char[] { 'S', 'F', 'C', 'S' }, new char[] { 'A', 'D', 'E', 'E' } }; + Assert.True(new Solution().Exist(input, "SEE")); + } + + [Fact] + public void Exist3() { + var input = new char[][] { new char[] { 'A', 'B', 'C', 'E' }, + new char[] { 'S', 'F', 'C', 'S' }, new char[] { 'A', 'D', 'E', 'E' } }; + Assert.False(new Solution().Exist(input, "ABCB")); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0084_largest_rectangle_in_histogram/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0084_largest_rectangle_in_histogram/SolutionTest.cs new file mode 100644 index 0000000..80b1437 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0084_largest_rectangle_in_histogram/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0001_0100.S0084_largest_rectangle_in_histogram { + +using Xunit; + +public class SolutionTest { + [Fact] + public void LargestRectangleArea() { + Assert.Equal(10, new Solution().LargestRectangleArea(new int[] { 2, 1, 5, 6, 2, 3 })); + } + + [Fact] + public void LargestRectangleArea2() { + Assert.Equal(4, new Solution().LargestRectangleArea(new int[] { 2, 4 })); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0094_binary_tree_inorder_traversal/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0094_binary_tree_inorder_traversal/SolutionTest.cs new file mode 100644 index 0000000..c4b0177 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0094_binary_tree_inorder_traversal/SolutionTest.cs @@ -0,0 +1,26 @@ +namespace LeetCodeNet.G0001_0100.S0094_binary_tree_inorder_traversal { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void InorderTraversal() { + TreeNode treeNode = new TreeNode(1); + TreeNode treeNode2 = new TreeNode(2); + treeNode.right = treeNode2; + treeNode2.left = new TreeNode(3); + Assert.Equal(new List { 1, 3, 2 }, new Solution().InorderTraversal(treeNode)); + } + + [Fact] + public void InorderTraversal2() { + Assert.Equal(new List { }, new Solution().InorderTraversal(null)); + } + + [Fact] + public void InorderTraversal3() { + Assert.Equal(new List { 1 }, new Solution().InorderTraversal(new TreeNode(1))); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0096_unique_binary_search_trees/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0096_unique_binary_search_trees/SolutionTest.cs new file mode 100644 index 0000000..0a94ae7 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0096_unique_binary_search_trees/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0001_0100.S0096_unique_binary_search_trees { + +using Xunit; + +public class SolutionTest { + [Fact] + public void NumTrees() { + Assert.Equal(5, new Solution().NumTrees(3)); + } + + [Fact] + public void NumTrees2() { + Assert.Equal(1, new Solution().NumTrees(1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0001_0100/S0098_validate_binary_search_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0001_0100/S0098_validate_binary_search_tree/SolutionTest.cs new file mode 100644 index 0000000..1c17457 --- /dev/null +++ b/LeetCodeNet.Tests/G0001_0100/S0098_validate_binary_search_tree/SolutionTest.cs @@ -0,0 +1,26 @@ +namespace LeetCodeNet.G0001_0100.S0098_validate_binary_search_tree { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void IsValidBST() { + TreeNode treeNode = new TreeNode(2); + treeNode.left = new TreeNode(1); + treeNode.right = new TreeNode(3); + Assert.True(new Solution().IsValidBST(treeNode)); + } + + [Fact] + public void IsValidBST2() { + TreeNode treeNode = new TreeNode(5); + treeNode.left = new TreeNode(1); + TreeNode treeNode2 = new TreeNode(4); + treeNode2.left = new TreeNode(3); + treeNode2.right = new TreeNode(6); + treeNode.right = treeNode2; + Assert.False(new Solution().IsValidBST(treeNode)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0101_symmetric_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0101_symmetric_tree/SolutionTest.cs new file mode 100644 index 0000000..e356e6f --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0101_symmetric_tree/SolutionTest.cs @@ -0,0 +1,29 @@ +namespace LeetCodeNet.G0101_0200.S0101_symmetric_tree { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void IsSymmetric() { + TreeNode treeNode = new TreeNode(1); + treeNode.left = new TreeNode(2); + treeNode.right = new TreeNode(2); + treeNode.left.left = new TreeNode(3); + treeNode.left.right = new TreeNode(4); + treeNode.right.left = new TreeNode(4); + treeNode.right.right = new TreeNode(3); + Assert.True(new Solution().IsSymmetric(treeNode)); + } + + [Fact] + public void IsSymmetric2() { + TreeNode treeNode = new TreeNode(1); + treeNode.left = new TreeNode(2); + treeNode.right = new TreeNode(2); + treeNode.left.right = new TreeNode(3); + treeNode.right.right = new TreeNode(3); + Assert.False(new Solution().IsSymmetric(treeNode)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0102_binary_tree_level_order_traversal/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0102_binary_tree_level_order_traversal/SolutionTest.cs new file mode 100644 index 0000000..52d2ebd --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0102_binary_tree_level_order_traversal/SolutionTest.cs @@ -0,0 +1,25 @@ +namespace LeetCodeNet.G0101_0200.S0102_binary_tree_level_order_traversal { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void LevelOrder() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 3, 9, 20, null, null, 15, 7 }); + Assert.Equal(new List> { new List { 3 }, new List { 9, 20 }, + new List { 15, 7 } }, new Solution().LevelOrder(root)); + } + + [Fact] + public void LevelOrder2() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 1 }); + Assert.Equal(new List> { new List { 1 } }, new Solution().LevelOrder(root)); + } + + [Fact] + public void LevelOrder3() { + Assert.Equal(new List> { }, new Solution().LevelOrder(null)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0104_maximum_depth_of_binary_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0104_maximum_depth_of_binary_tree/SolutionTest.cs new file mode 100644 index 0000000..f9a1f02 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0104_maximum_depth_of_binary_tree/SolutionTest.cs @@ -0,0 +1,19 @@ +namespace LeetCodeNet.G0101_0200.S0104_maximum_depth_of_binary_tree { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void MaxDepth() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 3, 9, 20, null, null, 15, 7 }); + Assert.Equal(3, new Solution().MaxDepth(root)); + } + + [Fact] + public void MaxDepth2() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 1, null, 2 }); + Assert.Equal(2, new Solution().MaxDepth(root)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/SolutionTest.cs new file mode 100644 index 0000000..49fd80a --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/SolutionTest.cs @@ -0,0 +1,24 @@ +namespace LeetCodeNet.G0101_0200.S0105_construct_binary_tree_from_preorder_and_inorder_traversal { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void BuildTree() { + int[] preorder = { 3, 9, 20, 15, 7 }; + int[] inorder = { 9, 3, 15, 20, 7 }; + TreeNode actual = new Solution().BuildTree(preorder, inorder); + Assert.Equal("3,9,20,15,7", actual.ToString()); + } + + [Fact] + public void BuildTree2() { + int[] preorder = { -1 }; + int[] inorder = { -1 }; + TreeNode actual = new Solution().BuildTree(preorder, inorder); + Assert.Equal("-1", actual.ToString()); + } + +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0114_flatten_binary_tree_to_linked_list/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0114_flatten_binary_tree_to_linked_list/SolutionTest.cs new file mode 100644 index 0000000..9e2d490 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0114_flatten_binary_tree_to_linked_list/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0101_0200.S0114_flatten_binary_tree_to_linked_list { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void Flatten() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 1, 2, 5, 3, 4, null, 6 }); + new Solution().Flatten(root); + Assert.Equal("1,null,2,null,3,null,4,null,5,null,6", root.ToString()); + } + + [Fact] + public void Flatten2() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 0 }); + new Solution().Flatten(root); + Assert.Equal("0", root.ToString()); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0121_best_time_to_buy_and_sell_stock/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0121_best_time_to_buy_and_sell_stock/SolutionTest.cs new file mode 100644 index 0000000..ac70dc0 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0121_best_time_to_buy_and_sell_stock/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0101_0200.S0121_best_time_to_buy_and_sell_stock { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MaxProfit() { + Assert.Equal(5, new Solution().MaxProfit(new int[] { 7, 1, 5, 3, 6, 4 })); + } + + [Fact] + public void MaxProfit2() { + Assert.Equal(0, new Solution().MaxProfit(new int[] { 7, 6, 4, 3, 1 })); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0124_binary_tree_maximum_path_sum/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0124_binary_tree_maximum_path_sum/SolutionTest.cs new file mode 100644 index 0000000..77c3bd6 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0124_binary_tree_maximum_path_sum/SolutionTest.cs @@ -0,0 +1,19 @@ +namespace LeetCodeNet.G0101_0200.S0124_binary_tree_maximum_path_sum { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void MaxPathSum() { + TreeNode treeNode = TreeNode.Create(new List {1, 2, 3}); + Assert.Equal(6, new Solution().MaxPathSum(treeNode)); + } + + [Fact] + public void MaxPathSum2() { + TreeNode treeNode = TreeNode.Create(new List {-10, 9, 20, null, null, 15, 7}); + Assert.Equal(42, new Solution().MaxPathSum(treeNode)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0128_longest_consecutive_sequence/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0128_longest_consecutive_sequence/SolutionTest.cs new file mode 100644 index 0000000..9ebb444 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0128_longest_consecutive_sequence/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0101_0200.S0128_longest_consecutive_sequence { + +using Xunit; + +public class SolutionTest { + [Fact] + public void LongestConsecutive() { + Assert.Equal(4, new Solution().LongestConsecutive(new int[] {100, 4, 200, 1, 3, 2})); + } + + [Fact] + public void LongestConsecutive2() { + Assert.Equal(9, new Solution().LongestConsecutive(new int[] {0, 3, 7, 2, 5, 8, 4, 6, 0, 1})); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0131_palindrome_partitioning/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0131_palindrome_partitioning/SolutionTest.cs new file mode 100644 index 0000000..723e61d --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0131_palindrome_partitioning/SolutionTest.cs @@ -0,0 +1,23 @@ +namespace LeetCodeNet.G0101_0200.S0131_palindrome_partitioning { + +using Xunit; + +public class SolutionTest { + [Fact] + public void Partition() { + Assert.Equal( + new List> { + new List {"a", "a", "b"}, + new List {"aa", "b"} + }, + new Solution().Partition("aab")); + } + + [Fact] + public void Partition2() { + Assert.Equal( + new List> {new List {"a"}}, + new Solution().Partition("a")); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0136_single_number/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0136_single_number/SolutionTest.cs new file mode 100644 index 0000000..f6026e1 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0136_single_number/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0101_0200.S0136_single_number { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SingleNumber() { + Assert.Equal(1, new Solution().SingleNumber(new int[] {2, 2, 1})); + } + + [Fact] + public void SingleNumber2() { + Assert.Equal(4, new Solution().SingleNumber(new int[] {4, 1, 2, 1, 2})); + } + + [Fact] + public void SingleNumber3() { + Assert.Equal(1, new Solution().SingleNumber(new int[] {1})); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0138_copy_list_with_random_pointer/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0138_copy_list_with_random_pointer/SolutionTest.cs new file mode 100644 index 0000000..3cedef7 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0138_copy_list_with_random_pointer/SolutionTest.cs @@ -0,0 +1,54 @@ +namespace LeetCodeNet.G0101_0200.S0138_copy_list_with_random_pointer { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void CopyRandomList() { + Node node7 = new Node(7); + Node node13 = new Node(13); + Node node11 = new Node(11); + Node node10 = new Node(10); + Node node1 = new Node(1); + node7.next = node13; + node13.next = node11; + node11.next = node10; + node10.next = node1; + node1.next = null; + node7.random = null; + node13.random = node7; + node11.random = node1; + node10.random = node11; + node1.random = node7; + Assert.Equal( + "[[7,null],[13,0],[11,4],[10,2],[1,0]]", + new Solution().CopyRandomList(node7).ToString()); + } + + [Fact] + public void CopyRandomList2() { + Node node1 = new Node(1); + Node node2 = new Node(2); + node1.next = node2; + node1.random = node1; + node2.next = null; + node2.random = node2; + Assert.Equal("[[1,1],[2,1]]", new Solution().CopyRandomList(node1).ToString()); + } + + [Fact] + public void CopyRandomList3() { + Node node31 = new Node(3); + Node node32 = new Node(3); + Node node33 = new Node(3); + node31.next = node32; + node31.random = null; + node32.next = node33; + node32.random = node31; + node33.next = null; + node33.random = null; + Assert.Equal("[[3,null],[3,0],[3,null]]", new Solution().CopyRandomList(node31).ToString()); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0139_word_break/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0139_word_break/SolutionTest.cs new file mode 100644 index 0000000..99ca9ab --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0139_word_break/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0101_0200.S0139_word_break { + +using Xunit; + +public class SolutionTest { + [Fact] + public void WordBreak() { + Assert.True(new Solution().WordBreak("leetcode", new List { "leet", "code" })); + } + + [Fact] + public void WordBreak2() { + Assert.True(new Solution().WordBreak("applepenapple", new List { "apple", "pen" })); + } + + [Fact] + public void WordBreak3() { + Assert.False(new Solution().WordBreak("catsandog", new List { "cats", "dog", "sand", "and", "cat" })); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0141_linked_list_cycle/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0141_linked_list_cycle/SolutionTest.cs new file mode 100644 index 0000000..6c81be6 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0141_linked_list_cycle/SolutionTest.cs @@ -0,0 +1,31 @@ +namespace LeetCodeNet.G0101_0200.S0141_linked_list_cycle { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void HasCycle() { + ListNode listNode1 = new ListNode(3); + listNode1.next = new ListNode(2); + listNode1.next.next = new ListNode(0); + listNode1.next.next.next = new ListNode(-4); + listNode1.next.next.next.next = listNode1.next; + Assert.True(new Solution().HasCycle(listNode1)); + } + + [Fact] + public void HasCycle2() { + ListNode listNode1 = new ListNode(1); + listNode1.next = new ListNode(2); + listNode1.next.next = listNode1; + Assert.True(new Solution().HasCycle(listNode1)); + } + + [Fact] + public void HasCycle3() { + ListNode listNode1 = new ListNode(1); + Assert.False(new Solution().HasCycle(listNode1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0142_linked_list_cycle_ii/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0142_linked_list_cycle_ii/SolutionTest.cs new file mode 100644 index 0000000..2ee511b --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0142_linked_list_cycle_ii/SolutionTest.cs @@ -0,0 +1,31 @@ +namespace LeetCodeNet.G0101_0200.S0142_linked_list_cycle_ii { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void DetectCycle() { + ListNode listNode1 = new ListNode(3); + listNode1.next = new ListNode(2); + listNode1.next.next = new ListNode(0); + listNode1.next.next.next = new ListNode(-4); + listNode1.next.next.next.next = listNode1.next; + Assert.True(new Solution().DetectCycle(listNode1) == listNode1.next); + } + + [Fact] + public void DetectCycle2() { + ListNode listNode1 = new ListNode(1); + listNode1.next = new ListNode(2); + listNode1.next.next = listNode1; + Assert.True(new Solution().DetectCycle(listNode1) == listNode1); + } + + [Fact] + public void DetectCycle3() { + ListNode listNode1 = new ListNode(1); + Assert.Null(new Solution().DetectCycle(listNode1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0146_lru_cache/LRUCacheTest.cs b/LeetCodeNet.Tests/G0101_0200/S0146_lru_cache/LRUCacheTest.cs new file mode 100644 index 0000000..39503fc --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0146_lru_cache/LRUCacheTest.cs @@ -0,0 +1,29 @@ +namespace LeetCodeNet.G0101_0200.S0146_lru_cache { + +using Xunit; + +public class LRUCacheTest { + [Fact] + public void LruCache() { + LRUCache lruCache = new LRUCache(2); + // cache is {1=1} + lruCache.Put(1, 1); + // cache is {1=1, 2=2} + lruCache.Put(2, 2); + // return 1 + Assert.Equal(1, lruCache.Get(1)); + // LRU key was 2, evicts key 2, cache is {1=1, 3=3} + lruCache.Put(3, 3); + // returns -1 (not found) + Assert.Equal(-1, lruCache.Get(2)); + // LRU key was 1, evicts key 1, cache is {4=4, 3=3} + lruCache.Put(4, 4); + // return -1 (not found) + Assert.Equal(-1, lruCache.Get(1)); + // return 3 + Assert.Equal(3, lruCache.Get(3)); + // return 4 + Assert.Equal(4, lruCache.Get(4)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0148_sort_list/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0148_sort_list/SolutionTest.cs new file mode 100644 index 0000000..65660d4 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0148_sort_list/SolutionTest.cs @@ -0,0 +1,31 @@ +namespace LeetCodeNet.G0101_0200.S0148_sort_list { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void SortList() { + ListNode listNode1 = new ListNode(4); + listNode1.next = new ListNode(2); + listNode1.next.next = new ListNode(1); + listNode1.next.next.next = new ListNode(3); + Assert.Equal("1, 2, 3, 4", new Solution().SortList(listNode1).ToString()); + } + + [Fact] + public void SortList2() { + ListNode listNode1 = new ListNode(-1); + listNode1.next = new ListNode(5); + listNode1.next.next = new ListNode(3); + listNode1.next.next.next = new ListNode(4); + listNode1.next.next.next.next = new ListNode(0); + Assert.Equal("-1, 0, 3, 4, 5", new Solution().SortList(listNode1).ToString()); + } + + [Fact] + public void SortList3() { + Assert.Null(new Solution().SortList(null)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0152_maximum_product_subarray/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0152_maximum_product_subarray/SolutionTest.cs new file mode 100644 index 0000000..746014b --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0152_maximum_product_subarray/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0101_0200.S0152_maximum_product_subarray { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MaxProduct() { + Assert.Equal(6, new Solution().MaxProduct(new int[] {2, 3, -2, 4})); + } + + [Fact] + public void MaxProduct2() { + Assert.Equal(0, new Solution().MaxProduct(new int[] {-2, 0, -1})); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/SolutionTest.cs new file mode 100644 index 0000000..97a4c51 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0101_0200.S0153_find_minimum_in_rotated_sorted_array { + +using Xunit; + +public class SolutionTest { + [Fact] + public void FindMin() { + Assert.Equal(1, new Solution().FindMin(new int[] {3, 4, 5, 1, 2})); + } + + [Fact] + public void FindMin2() { + Assert.Equal(0, new Solution().FindMin(new int[] {4, 5, 6, 7, 0, 1, 2})); + } + + [Fact] + public void FindMin3() { + Assert.Equal(11, new Solution().FindMin(new int[] {11, 13, 15, 17})); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0155_min_stack/MinStackTest.cs b/LeetCodeNet.Tests/G0101_0200/S0155_min_stack/MinStackTest.cs new file mode 100644 index 0000000..1b72a85 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0155_min_stack/MinStackTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0101_0200.S0155_min_stack { + +using Xunit; + +public class MinStackTest { + [Fact] + public void MinStack() { + MinStack minStack = new MinStack(); + minStack.Push(-2); + minStack.Push(0); + minStack.Push(-3); + // return -3 + Assert.Equal(-3, minStack.GetMin()); + minStack.Pop(); + // return 0 + Assert.Equal(0, minStack.Top()); + // return -2 + Assert.Equal(-2, minStack.GetMin()); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0160_intersection_of_two_linked_lists/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0160_intersection_of_two_linked_lists/SolutionTest.cs new file mode 100644 index 0000000..b547040 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0160_intersection_of_two_linked_lists/SolutionTest.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0101_0200.S0160_intersection_of_two_linked_lists { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void GetIntersectionNode() { + ListNode intersectionListNode = new ListNode(8, new ListNode(4, new ListNode(5))); + ListNode nodeA = new ListNode(4, new ListNode(1, intersectionListNode)); + ListNode nodeB = new ListNode(5, new ListNode(6, new ListNode(1, intersectionListNode))); + Assert.Equal(8, new Solution().GetIntersectionNode(nodeA, nodeB).val); + } + + [Fact] + public void GetIntersectionNode2() { + ListNode nodeA = new ListNode(4, new ListNode(1, new ListNode(2))); + ListNode nodeB = new ListNode(5, new ListNode(6, new ListNode(1, new ListNode(2)))); + Assert.Equal(null, new Solution().GetIntersectionNode(nodeA, nodeB)); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0169_majority_element/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0169_majority_element/SolutionTest.cs new file mode 100644 index 0000000..51182de --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0169_majority_element/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0101_0200.S0169_majority_element { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MajorityElement() { + Assert.Equal(3, new Solution().MajorityElement(new int[] {3, 2, 3})); + } + + [Fact] + public void MajorityElement2() { + Assert.Equal(2, new Solution().MajorityElement(new int[] {2, 2, 1, 1, 1, 2, 2})); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0189_rotate_array/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0189_rotate_array/SolutionTest.cs new file mode 100644 index 0000000..e80e04c --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0189_rotate_array/SolutionTest.cs @@ -0,0 +1,20 @@ +namespace LeetCodeNet.G0101_0200.S0189_rotate_array { + +using Xunit; + +public class SolutionTest { + [Fact] + public void Rotate() { + int[] array = new int[] {1, 2, 3, 4, 5, 6, 7}; + new Solution().Rotate(array, 3); + Assert.Equal(new int[] {5, 6, 7, 1, 2, 3, 4}, array); + } + + [Fact] + public void Rotate2() { + int[] array = new int[] {-1, -100, 3, 99}; + new Solution().Rotate(array, 2); + Assert.Equal(new int[] {3, 99, -1, -100}, array); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0198_house_robber/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0198_house_robber/SolutionTest.cs new file mode 100644 index 0000000..23ef2b0 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0198_house_robber/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0101_0200.S0198_house_robber { + +using Xunit; + +public class SolutionTest { + [Fact] + public void Rob() { + Assert.Equal(4, new Solution().Rob(new int[] {1, 2, 3, 1})); + } + + [Fact] + public void Rob2() { + Assert.Equal(12, new Solution().Rob(new int[] {2, 7, 9, 3, 1})); + } +} +} diff --git a/LeetCodeNet.Tests/G0101_0200/S0200_number_of_islands/SolutionTest.cs b/LeetCodeNet.Tests/G0101_0200/S0200_number_of_islands/SolutionTest.cs new file mode 100644 index 0000000..91d4c65 --- /dev/null +++ b/LeetCodeNet.Tests/G0101_0200/S0200_number_of_islands/SolutionTest.cs @@ -0,0 +1,28 @@ +namespace LeetCodeNet.G0101_0200.S0200_number_of_islands { + +using Xunit; + +public class SolutionTest { + [Fact] + public void NumIslands() { + char[][] grid = new char[][] { + new char[] {'1', '1', '1', '1', '0'}, + new char[] {'1', '1', '0', '1', '0'}, + new char[] {'1', '1', '0', '0', '0'}, + new char[] {'0', '0', '0', '0', '0'} + }; + Assert.Equal(1, new Solution().NumIslands(grid)); + } + + [Fact] + public void NumIslands2() { + char[][] grid = new char[][] { + new char[] {'1', '1', '0', '0', '0'}, + new char[] {'1', '1', '0', '0', '0'}, + new char[] {'0', '0', '1', '0', '0'}, + new char[] {'0', '0', '0', '1', '1'} + }; + Assert.Equal(3, new Solution().NumIslands(grid)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0206_reverse_linked_list/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0206_reverse_linked_list/SolutionTest.cs new file mode 100644 index 0000000..b6ab4b6 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0206_reverse_linked_list/SolutionTest.cs @@ -0,0 +1,29 @@ +namespace LeetCodeNet.G0201_0300.S0206_reverse_linked_list { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void ReverseList() { + ListNode headActual = new ListNode(1); + headActual.next = new ListNode(2); + headActual.next.next = new ListNode(3); + headActual.next.next.next = new ListNode(4); + headActual.next.next.next.next = new ListNode(5); + Assert.Equal("5, 4, 3, 2, 1", new Solution().ReverseList(headActual).ToString()); + } + + [Fact] + public void ReverseList2() { + ListNode headActual = new ListNode(1); + headActual.next = new ListNode(2); + Assert.Equal("2, 1", new Solution().ReverseList(headActual).ToString()); + } + + [Fact] + public void ReverseList3() { + Assert.Null(new Solution().ReverseList(null)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0207_course_schedule/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0207_course_schedule/SolutionTest.cs new file mode 100644 index 0000000..d526dee --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0207_course_schedule/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0201_0300.S0207_course_schedule { + +using Xunit; + +public class SolutionTest { + [Fact] + public void CanFinish() { + Assert.True(new Solution().CanFinish(2, new int[][] { new int[] { 1, 0 } })); + } + + [Fact] + public void CanFinish2() { + Assert.False(new Solution().CanFinish(2, new int[][] { new int[] { 1, 0 }, new int[] { 0, 1 } })); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0208_implement_trie_prefix_tree/TrieTest.cs b/LeetCodeNet.Tests/G0201_0300/S0208_implement_trie_prefix_tree/TrieTest.cs new file mode 100644 index 0000000..ecd27c7 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0208_implement_trie_prefix_tree/TrieTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0201_0300.S0208_implement_trie_prefix_tree { + +using Xunit; + +public class TrieTest { + [Fact] + public void Trie() { + Trie trie = new Trie(); + trie.Insert("apple"); + // return True + Assert.True(trie.Search("apple")); + // return False + Assert.False(trie.Search("app")); + // return True + Assert.True(trie.StartsWith("app")); + trie.Insert("app"); + // return True + Assert.True(trie.Search("app")); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0215_kth_largest_element_in_an_array/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0215_kth_largest_element_in_an_array/SolutionTest.cs new file mode 100644 index 0000000..2b4db62 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0215_kth_largest_element_in_an_array/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0201_0300.S0215_kth_largest_element_in_an_array { + +using Xunit; + +public class SolutionTest { + [Fact] + public void FindKthLargest() { + Assert.Equal(5, new Solution().FindKthLargest(new int[] { 3, 2, 1, 5, 6, 4 }, 2)); + } + + [Fact] + public void FindKthLargest2() { + Assert.Equal(4, new Solution().FindKthLargest(new int[] { 3, 2, 3, 1, 2, 4, 5, 5, 6 }, 4)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0221_maximal_square/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0221_maximal_square/SolutionTest.cs new file mode 100644 index 0000000..5ece432 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0221_maximal_square/SolutionTest.cs @@ -0,0 +1,29 @@ +namespace LeetCodeNet.G0201_0300.S0221_maximal_square { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MaximalSquare() { + char[][] input = { + new[] {'1', '0', '1', '0', '0'}, + new[] {'1', '0', '1', '1', '1'}, + new[] {'1', '1', '1', '1', '1'}, + new[] {'1', '0', '0', '1', '0'} + }; + Assert.Equal(4, new Solution().MaximalSquare(input)); + } + + [Fact] + public void MaximalSquare2() { + char[][] input = { new[] {'0', '1'}, new[] {'1', '0'} }; + Assert.Equal(1, new Solution().MaximalSquare(input)); + } + + [Fact] + public void MaximalSquare3() { + char[][] input = { new[] {'0'} }; + Assert.Equal(0, new Solution().MaximalSquare(input)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0226_invert_binary_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0226_invert_binary_tree/SolutionTest.cs new file mode 100644 index 0000000..937b2cc --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0226_invert_binary_tree/SolutionTest.cs @@ -0,0 +1,19 @@ +namespace LeetCodeNet.G0201_0300.S0226_invert_binary_tree { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void InvertTree() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 4, 2, 7, 1, 3, 6, 9 }); + Assert.Equal("4,7,9,6,2,3,1", new Solution().InvertTree(root).ToString()); + } + + [Fact] + public void InvertTree2() { + TreeNode root = TreeUtils.ConstructBinaryTree(new List { 2, 1, 3 }); + Assert.Equal("2,3,1", new Solution().InvertTree(root).ToString()); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0230_kth_smallest_element_in_a_bst/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0230_kth_smallest_element_in_a_bst/SolutionTest.cs new file mode 100644 index 0000000..b28cf17 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0230_kth_smallest_element_in_a_bst/SolutionTest.cs @@ -0,0 +1,19 @@ +namespace LeetCodeNet.G0201_0300.S0230_kth_smallest_element_in_a_bst { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void KthSmallest() { + TreeNode root = TreeNode.Create(new List { 3, 1, 4, null, 2 }); + Assert.Equal(1, new Solution().KthSmallest(root, 1)); + } + + [Fact] + public void KthSmallest2() { + TreeNode root = TreeNode.Create(new List { 5, 3, 6, 2, 4, null, null, 1 }); + Assert.Equal(3, new Solution().KthSmallest(root, 3)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0234_palindrome_linked_list/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0234_palindrome_linked_list/SolutionTest.cs new file mode 100644 index 0000000..03f8e96 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0234_palindrome_linked_list/SolutionTest.cs @@ -0,0 +1,23 @@ +namespace LeetCodeNet.G0201_0300.S0234_palindrome_linked_list { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void IsPalindrome() { + ListNode headActual = new ListNode(1); + headActual.next = new ListNode(2); + headActual.next.next = new ListNode(2); + headActual.next.next.next = new ListNode(1); + Assert.True(new Solution().IsPalindrome(headActual)); + } + + [Fact] + public void IsPalindrome2() { + ListNode headActual = new ListNode(1); + headActual.next = new ListNode(2); + Assert.False(new Solution().IsPalindrome(headActual)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/SolutionTest.cs new file mode 100644 index 0000000..df92cd8 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/SolutionTest.cs @@ -0,0 +1,36 @@ +namespace LeetCodeNet.G0201_0300.S0236_lowest_common_ancestor_of_a_binary_tree { + +using Xunit; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void LowestCommonAncestor() { + TreeNode leftNodeLeftNode = new TreeNode(6); + TreeNode leftNodeRightNode = new TreeNode(2, new TreeNode(7), new TreeNode(4)); + TreeNode leftNode = new TreeNode(5, leftNodeLeftNode, leftNodeRightNode); + TreeNode rightNode = new TreeNode(1, new TreeNode(0), new TreeNode(8)); + TreeNode root = new TreeNode(3, leftNode, rightNode); + Assert.Equal(3, new Solution().LowestCommonAncestor(root, new TreeNode(5), new TreeNode(1)).val); + } + + [Fact] + public void LowestCommonAncestor2() { + TreeNode leftNodeLeftNode = new TreeNode(6); + TreeNode leftNodeRightNode = new TreeNode(2, new TreeNode(7), new TreeNode(4)); + TreeNode leftNode = new TreeNode(5, leftNodeLeftNode, leftNodeRightNode); + TreeNode rightNode = new TreeNode(1, new TreeNode(0), new TreeNode(8)); + TreeNode root = new TreeNode(3, leftNode, rightNode); + Assert.Equal(5, new Solution().LowestCommonAncestor(root, new TreeNode(5), new TreeNode(4)).val); + } + + [Fact] + public void LowestCommonAncestor3() { + Assert.Equal(2, + new Solution().LowestCommonAncestor( + new TreeNode(2, new TreeNode(1), null), + new TreeNode(2), + new TreeNode(1)).val); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0238_product_of_array_except_self/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0238_product_of_array_except_self/SolutionTest.cs new file mode 100644 index 0000000..6378e43 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0238_product_of_array_except_self/SolutionTest.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0201_0300.S0238_product_of_array_except_self { + +using Xunit; + +public class SolutionTest { + [Fact] + public void ProductExceptSelf() { + Assert.Equal( + new int[] { 24, 12, 8, 6 }, + new Solution().ProductExceptSelf(new int[] { 1, 2, 3, 4 }) + ); + } + + [Fact] + public void ProductExceptSelf2() { + Assert.Equal( + new int[] { 0, 0, 9, 0, 0 }, + new Solution().ProductExceptSelf(new int[] { -1, 1, 0, -3, 3 }) + ); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0239_sliding_window_maximum/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0239_sliding_window_maximum/SolutionTest.cs new file mode 100644 index 0000000..ea6e9aa --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0239_sliding_window_maximum/SolutionTest.cs @@ -0,0 +1,17 @@ +namespace LeetCodeNet.G0201_0300.S0239_sliding_window_maximum { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MaxSlidingWindow() { + Assert.Equal(new int[] {3, 3, 5, 5, 6, 7}, + new Solution().MaxSlidingWindow(new int[] {1, 3, -1, -3, 5, 3, 6, 7}, 3)); + } + + [Fact] + public void MaxSlidingWindow2() { + Assert.Equal(new int[] {1}, new Solution().MaxSlidingWindow(new int[] {1}, 1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0240_search_a_2d_matrix_ii/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0240_search_a_2d_matrix_ii/SolutionTest.cs new file mode 100644 index 0000000..95a01d8 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0240_search_a_2d_matrix_ii/SolutionTest.cs @@ -0,0 +1,30 @@ +namespace LeetCodeNet.G0201_0300.S0240_search_a_2d_matrix_ii { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SearchMatrix() { + int[][] matrix = { + new int[] {1, 4, 7, 11, 15}, + new int[] {2, 5, 8, 12, 19}, + new int[] {3, 6, 9, 16, 22}, + new int[] {10, 13, 14, 17, 24}, + new int[] {18, 21, 23, 26, 30} + }; + Assert.True(new Solution().SearchMatrix(matrix, 5)); + } + + [Fact] + public void SearchMatrix2() { + int[][] matrix = { + new int[] {1, 4, 7, 11, 15}, + new int[] {2, 5, 8, 12, 19}, + new int[] {3, 6, 9, 16, 22}, + new int[] {10, 13, 14, 17, 24}, + new int[] {18, 21, 23, 26, 30} + }; + Assert.False(new Solution().SearchMatrix(matrix, 20)); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0283_move_zeroes/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0283_move_zeroes/SolutionTest.cs new file mode 100644 index 0000000..9bf36ff --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0283_move_zeroes/SolutionTest.cs @@ -0,0 +1,20 @@ +namespace LeetCodeNet.G0201_0300.S0283_move_zeroes { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MoveZeroes() { + int[] array = {0, 1, 0, 3, 12}; + new Solution().MoveZeroes(array); + Assert.Equal(new int[] {1, 3, 12, 0, 0}, array); + } + + [Fact] + public void MoveZeroes2() { + int[] array = {0}; + new Solution().MoveZeroes(array); + Assert.Equal(new int[] {0}, array); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0287_find_the_duplicate_number/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0287_find_the_duplicate_number/SolutionTest.cs new file mode 100644 index 0000000..464e888 --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0287_find_the_duplicate_number/SolutionTest.cs @@ -0,0 +1,26 @@ +namespace LeetCodeNet.G0201_0300.S0287_find_the_duplicate_number { + +using Xunit; + +public class SolutionTest { + [Fact] + public void FindDuplicate() { + Assert.Equal(2, new Solution().FindDuplicate(new int[] {1, 3, 4, 2, 2})); + } + + [Fact] + public void FindDuplicate2() { + Assert.Equal(3, new Solution().FindDuplicate(new int[] {3, 1, 3, 4, 2})); + } + + [Fact] + public void FindDuplicate3() { + Assert.Equal(1, new Solution().FindDuplicate(new int[] {1, 1})); + } + + [Fact] + public void FindDuplicate4() { + Assert.Equal(1, new Solution().FindDuplicate(new int[] {1, 1, 2})); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0295_find_median_from_data_stream/MedianFinderTest.cs b/LeetCodeNet.Tests/G0201_0300/S0295_find_median_from_data_stream/MedianFinderTest.cs new file mode 100644 index 0000000..6f1ab2f --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0295_find_median_from_data_stream/MedianFinderTest.cs @@ -0,0 +1,30 @@ +namespace LeetCodeNet.G0201_0300.S0295_find_median_from_data_stream { + +using Xunit; + +public class MedianFinderTest { + [Fact] + public void MedianFinder() { + MedianFinder medianFinder = new MedianFinder(); + // arr = [1] + medianFinder.AddNum(1); + // arr = [1, 2] + medianFinder.AddNum(2); + // return 1.5 (i.e., (1 + 2) / 2) + Assert.Equal(1.5, medianFinder.FindMedian()); + // arr[1, 2, 3] + medianFinder.AddNum(3); + // return 2.0 + Assert.Equal(2.0, medianFinder.FindMedian()); + } + + [Fact] + public void MedianFinder2() { + MedianFinder medianFinder = new MedianFinder(); + medianFinder.AddNum(1); + medianFinder.AddNum(3); + medianFinder.AddNum(-1); + Assert.Equal(1.0, medianFinder.FindMedian()); + } +} +} diff --git a/LeetCodeNet.Tests/G0201_0300/S0300_longest_increasing_subsequence/SolutionTest.cs b/LeetCodeNet.Tests/G0201_0300/S0300_longest_increasing_subsequence/SolutionTest.cs new file mode 100644 index 0000000..ace189f --- /dev/null +++ b/LeetCodeNet.Tests/G0201_0300/S0300_longest_increasing_subsequence/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0201_0300.S0300_longest_increasing_subsequence { + +using Xunit; + +public class SolutionTest { + [Fact] + public void LengthOfLIS() { + Assert.Equal(4, new Solution().LengthOfLIS(new int[] {10, 9, 2, 5, 3, 7, 101, 18})); + } + + [Fact] + public void LengthOfLIS2() { + Assert.Equal(4, new Solution().LengthOfLIS(new int[] {0, 1, 0, 3, 2, 3})); + } + + [Fact] + public void LengthOfLIS3() { + Assert.Equal(1, new Solution().LengthOfLIS(new int[] {7, 7, 7, 7, 7, 7, 7})); + } +} +} diff --git a/LeetCodeNet.Tests/G0301_0400/S0322_coin_change/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0322_coin_change/SolutionTest.cs new file mode 100644 index 0000000..397e3e7 --- /dev/null +++ b/LeetCodeNet.Tests/G0301_0400/S0322_coin_change/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0301_0400.S0322_coin_change { + +using Xunit; + +public class SolutionTest { + [Fact] + public void CoinChange() { + Assert.Equal(3, new Solution().CoinChange(new int[] {1, 2, 5}, 11)); + } + + [Fact] + public void CoinChange2() { + Assert.Equal(-1, new Solution().CoinChange(new int[] {2}, 3)); + } + + [Fact] + public void CoinChange3() { + Assert.Equal(0, new Solution().CoinChange(new int[] {1}, 0)); + } +} +} diff --git a/LeetCodeNet.Tests/G0301_0400/S0338_counting_bits/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0338_counting_bits/SolutionTest.cs new file mode 100644 index 0000000..f4f4bb0 --- /dev/null +++ b/LeetCodeNet.Tests/G0301_0400/S0338_counting_bits/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0301_0400.S0338_counting_bits { + +using Xunit; + +public class SolutionTest { + [Fact] + public void CountBits() { + Assert.Equal(new int[] {0, 1, 1}, new Solution().CountBits(2)); + } + + [Fact] + public void CountBits2() { + Assert.Equal(new int[] {0, 1, 1, 2, 1, 2}, new Solution().CountBits(5)); + } +} +} diff --git a/LeetCodeNet.Tests/G0301_0400/S0347_top_k_frequent_elements/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0347_top_k_frequent_elements/SolutionTest.cs new file mode 100644 index 0000000..325170a --- /dev/null +++ b/LeetCodeNet.Tests/G0301_0400/S0347_top_k_frequent_elements/SolutionTest.cs @@ -0,0 +1,17 @@ +namespace LeetCodeNet.G0301_0400.S0347_top_k_frequent_elements { + +using Xunit; + +public class SolutionTest { + [Fact] + public void TopKFrequent() { + Assert.Equal(new int[] {1, 2}, + new Solution().TopKFrequent(new int[] {1, 1, 1, 2, 2, 3}, 2)); + } + + [Fact] + public void TopKFrequent2() { + Assert.Equal(new int[] {1}, new Solution().TopKFrequent(new int[] {1}, 1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0301_0400/S0394_decode_string/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0394_decode_string/SolutionTest.cs new file mode 100644 index 0000000..5c34223 --- /dev/null +++ b/LeetCodeNet.Tests/G0301_0400/S0394_decode_string/SolutionTest.cs @@ -0,0 +1,26 @@ +namespace LeetCodeNet.G0301_0400.S0394_decode_string { + +using Xunit; + +public class SolutionTest { + [Fact] + public void DecodeString() { + Assert.Equal("aaabcbc", new Solution().DecodeString("3[a]2[bc]")); + } + + [Fact] + public void DecodeString2() { + Assert.Equal("accaccacc", new Solution().DecodeString("3[a2[c]]")); + } + + [Fact] + public void DecodeString3() { + Assert.Equal("abcabccdcdcdef", new Solution().DecodeString("2[abc]3[cd]ef")); + } + + [Fact] + public void DecodeString4() { + Assert.Equal("abccdcdcdxyz", new Solution().DecodeString("abc3[cd]xyz")); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0416_partition_equal_subset_sum/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0416_partition_equal_subset_sum/SolutionTest.cs new file mode 100644 index 0000000..d481a5c --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0416_partition_equal_subset_sum/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0401_0500.S0416_partition_equal_subset_sum { + +using Xunit; + +public class SolutionTest { + [Fact] + public void CanPartition() { + Assert.True(new Solution().CanPartition(new int[] {1, 5, 11, 5})); + } + + [Fact] + public void CanPartition2() { + Assert.False(new Solution().CanPartition(new int[] {1, 2, 3, 5})); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0437_path_sum_iii/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0437_path_sum_iii/SolutionTest.cs new file mode 100644 index 0000000..9fcfac6 --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0437_path_sum_iii/SolutionTest.cs @@ -0,0 +1,20 @@ +namespace LeetCodeNet.G0401_0500.S0437_path_sum_iii { + +using Xunit; +using System.Collections.Generic; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void PathSum() { + Assert.Equal(3, new Solution().PathSum( + TreeNode.Create(new List {10, 5, -3, 3, 2, null, 11, 3, -2, null, 1}), 8)); + } + + [Fact] + public void PathSum2() { + Assert.Equal(3, new Solution().PathSum( + TreeNode.Create(new List {5, 4, 8, 11, null, 13, 4, 7, 2, null, null, 5, 1}), 22)); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0438_find_all_anagrams_in_a_string/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0438_find_all_anagrams_in_a_string/SolutionTest.cs new file mode 100644 index 0000000..8b6e6f5 --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0438_find_all_anagrams_in_a_string/SolutionTest.cs @@ -0,0 +1,20 @@ +namespace LeetCodeNet.G0401_0500.S0438_find_all_anagrams_in_a_string { + +using System.Collections.Generic; +using Xunit; + +public class SolutionTest +{ + [Fact] + public void FindAnagrams() + { + Assert.Equal(new List {0, 6}, new Solution().FindAnagrams("cbaebabacd", "abc")); + } + + [Fact] + public void FindAnagrams2() + { + Assert.Equal(new List {0, 1, 2}, new Solution().FindAnagrams("abab", "ab")); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0494_target_sum/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0494_target_sum/SolutionTest.cs new file mode 100644 index 0000000..6fed602 --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0494_target_sum/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0401_0500.S0494_target_sum { + +using Xunit; + +public class SolutionTest { + [Fact] + public void FindTargetSumWays() { + Assert.Equal(5, new Solution().FindTargetSumWays(new int[] {1, 1, 1, 1, 1}, 3)); + } + + [Fact] + public void FindTargetSumWays2() { + Assert.Equal(1, new Solution().FindTargetSumWays(new int[] {1}, 1)); + } +} +} diff --git a/LeetCodeNet.Tests/G0501_0600/S0543_diameter_of_binary_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0501_0600/S0543_diameter_of_binary_tree/SolutionTest.cs new file mode 100644 index 0000000..4ca6527 --- /dev/null +++ b/LeetCodeNet.Tests/G0501_0600/S0543_diameter_of_binary_tree/SolutionTest.cs @@ -0,0 +1,18 @@ +namespace LeetCodeNet.G0501_0600.S0543_diameter_of_binary_tree { + +using Xunit; +using System.Collections.Generic; +using LeetCodeNet.Com_github_leetcode; + +public class SolutionTest { + [Fact] + public void DiameterOfBinaryTree() { + Assert.Equal(3, new Solution().DiameterOfBinaryTree(TreeNode.Create(new List {1, 2, 3, 4, 5}))); + } + + [Fact] + public void DiameterOfBinaryTree2() { + Assert.Equal(1, new Solution().DiameterOfBinaryTree(TreeNode.Create(new List {1, 2}))); + } +} +} diff --git a/LeetCodeNet.Tests/G0501_0600/S0560_subarray_sum_equals_k/SolutionTest.cs b/LeetCodeNet.Tests/G0501_0600/S0560_subarray_sum_equals_k/SolutionTest.cs new file mode 100644 index 0000000..2c58a37 --- /dev/null +++ b/LeetCodeNet.Tests/G0501_0600/S0560_subarray_sum_equals_k/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0501_0600.S0560_subarray_sum_equals_k { + +using Xunit; + +public class SolutionTest { + [Fact] + public void SubarraySum() { + Assert.Equal(2, new Solution().SubarraySum(new int[] {1, 1, 1}, 2)); + } + + [Fact] + public void SubarraySum2() { + Assert.Equal(2, new Solution().SubarraySum(new int[] {1, 2, 3}, 3)); + } +} +} diff --git a/LeetCodeNet.Tests/G0601_0700/S0647_palindromic_substrings/SolutionTest.cs b/LeetCodeNet.Tests/G0601_0700/S0647_palindromic_substrings/SolutionTest.cs new file mode 100644 index 0000000..d51adb7 --- /dev/null +++ b/LeetCodeNet.Tests/G0601_0700/S0647_palindromic_substrings/SolutionTest.cs @@ -0,0 +1,16 @@ +namespace LeetCodeNet.G0601_0700.S0647_palindromic_substrings { + +using Xunit; + +public class SolutionTest { + [Fact] + public void CountSubstrings() { + Assert.Equal(3, new Solution().CountSubstrings("abc")); + } + + [Fact] + public void CountSubstrings2() { + Assert.Equal(6, new Solution().CountSubstrings("aaa")); + } +} +} diff --git a/LeetCodeNet.Tests/G0701_0800/S0739_daily_temperatures/SolutionTest.cs b/LeetCodeNet.Tests/G0701_0800/S0739_daily_temperatures/SolutionTest.cs new file mode 100644 index 0000000..dc17e02 --- /dev/null +++ b/LeetCodeNet.Tests/G0701_0800/S0739_daily_temperatures/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0701_0800.S0739_daily_temperatures { + +using Xunit; + +public class SolutionTest { + [Fact] + public void DailyTemperatures() { + Assert.Equal(new int[] {1, 1, 4, 2, 1, 1, 0, 0}, new Solution().DailyTemperatures(new int[] {73, 74, 75, 71, 69, 72, 76, 73})); + } + + [Fact] + public void DailyTemperatures2() { + Assert.Equal(new int[] {1, 1, 1, 0}, new Solution().DailyTemperatures(new int[] {30, 40, 50, 60})); + } + + [Fact] + public void DailyTemperatures3() { + Assert.Equal(new int[] {1, 1, 0}, new Solution().DailyTemperatures(new int[] {30, 60, 90})); + } +} +} diff --git a/LeetCodeNet.Tests/G0701_0800/S0763_partition_labels/SolutionTest.cs b/LeetCodeNet.Tests/G0701_0800/S0763_partition_labels/SolutionTest.cs new file mode 100644 index 0000000..2c6cca9 --- /dev/null +++ b/LeetCodeNet.Tests/G0701_0800/S0763_partition_labels/SolutionTest.cs @@ -0,0 +1,17 @@ +namespace LeetCodeNet.G0701_0800.S0763_partition_labels { + +using Xunit; +using System.Collections.Generic; + +public class SolutionTest { + [Fact] + public void PartitionLabels() { + Assert.Equal(new List {9, 7, 8}, new Solution().PartitionLabels("ababcbacadefegdehijhklij")); + } + + [Fact] + public void PartitionLabels2() { + Assert.Equal(new List {10}, new Solution().PartitionLabels("eccbbbbdec")); + } +} +} diff --git a/LeetCodeNet.Tests/G1101_1200/S1143_longest_common_subsequence/SolutionTest.cs b/LeetCodeNet.Tests/G1101_1200/S1143_longest_common_subsequence/SolutionTest.cs new file mode 100644 index 0000000..2537a08 --- /dev/null +++ b/LeetCodeNet.Tests/G1101_1200/S1143_longest_common_subsequence/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G1101_1200.S1143_longest_common_subsequence { + +using Xunit; + +public class SolutionTest { + [Fact] + public void LongestCommonSubsequence() { + Assert.Equal(3, new Solution().LongestCommonSubsequence("abcde", "ace")); + } + + [Fact] + public void LongestCommonSubsequence2() { + Assert.Equal(3, new Solution().LongestCommonSubsequence("abc", "abc")); + } + + [Fact] + public void LongestCommonSubsequence3() { + Assert.Equal(0, new Solution().LongestCommonSubsequence("abc", "def")); + } +} +} diff --git a/LeetCodeNet/Com_github_leetcode/Node.cs b/LeetCodeNet/Com_github_leetcode/Node.cs new file mode 100644 index 0000000..e5e5487 --- /dev/null +++ b/LeetCodeNet/Com_github_leetcode/Node.cs @@ -0,0 +1,57 @@ +namespace LeetCodeNet.Com_github_leetcode { + +public class Node { + public int val; + public Node next; + public Node random; + + public Node() { + this.val = 0; + } + + public Node(int val) { + this.val = val; + } + + public Node(int val, Node next, Node random) { + this.val = val; + this.next = next; + this.random = random; + } + + public override string ToString() { + List result = new List{}; + List result2 = new List { + val.ToString() + }; + if (random == null) { + result2.Add("null"); + } else { + result2.Add(random.val.ToString()); + } + string result2String = "[" + string.Join(",", result2) + "]"; + result.Add(result2String); + Node curr = next; + while (curr != null) { + List result3 = new List { + curr.val.ToString() + }; + if (curr.random == null) { + result3.Add("null"); + } else { + int randomIndex = 0; + Node curr2 = this; + while (curr2.next != null && curr2 != curr.random) { + randomIndex += 1; + curr2 = curr2.next; + } + result3.Add(randomIndex.ToString()); + } + string result3String = "[" + string.Join(",", result3) + "]"; + result.Add(result3String); + curr = curr.next; + } + return "[" + string.Join(",", result) + "]"; + } +} +} \ No newline at end of file diff --git a/LeetCodeNet/Com_github_leetcode/TreeNode.cs b/LeetCodeNet/Com_github_leetcode/TreeNode.cs new file mode 100644 index 0000000..a093e40 --- /dev/null +++ b/LeetCodeNet/Com_github_leetcode/TreeNode.cs @@ -0,0 +1,58 @@ +namespace LeetCodeNet.Com_github_leetcode { + +using System; +using System.Collections.Generic; + +public class TreeNode { + public int? val; + public TreeNode left; + public TreeNode right; + + public TreeNode(int? val) { + this.val = val; + } + + public TreeNode(int val, TreeNode left, TreeNode right) { + this.val = val; + this.left = left; + this.right = right; + } + + public static TreeNode Create(List treeValues) { + TreeNode root = treeValues.Count == 0 ? null : new TreeNode(treeValues[0]); + Queue queue = new Queue(); + queue.Enqueue(root); + int i = 1; + while (i < treeValues.Count) { + TreeNode curr = queue.Dequeue(); + if (treeValues[i] != null) { + curr.left = new TreeNode(treeValues[i]); + queue.Enqueue(curr.left); + } + if (++i < treeValues.Count && treeValues[i] != null) { + curr.right = new TreeNode(treeValues[i]); + queue.Enqueue(curr.right); + } + i++; + } + return root; + } + + public override string ToString() { + if (left == null && right == null) { + return "" + val; + } else { + string root = "" + val; + string leftValue = "null"; + string rightValue = "null"; + if (left != null) { + leftValue = left.ToString(); + } + if (right != null) { + rightValue = right.ToString(); + } + return root + "," + leftValue + "," + rightValue; + } + } +} +} diff --git a/LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs b/LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs index 687719f..8b39fa9 100644 --- a/LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs @@ -1,8 +1,9 @@ namespace LeetCodeNet.G0001_0100.S0001_two_sum { // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table -// #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Big_O_Time_O(n)_Space_O(n) -// #2023_12_18_Time_134_ms_(81.26%)_Space_44.8_MB_(19.72%) +// #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Top_Interview_150_Hashmap +// #Big_O_Time_O(n)_Space_O(n) #AI_can_be_used_to_solve_the_task +// #2025_06_12_Time_1_ms_(98.51%)_Space_49.32_MB_(14.31%) public class Solution { public int[] TwoSum(int[] numbers, int target) { @@ -18,4 +19,3 @@ public int[] TwoSum(int[] numbers, int target) { } } } - \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs b/LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs index 711a974..068ad25 100644 --- a/LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs @@ -2,10 +2,21 @@ namespace LeetCodeNet.G0001_0100.S0002_add_two_numbers { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion // #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15 -// #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) #2023_12_19_Time_84_ms_(77.30%)_Space_49.4_MB_(51.01%) +// #Top_Interview_150_Linked_List #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) +// #AI_can_be_used_to_solve_the_task #2025_06_12_Time_1_ms_(91.39%)_Space_54.13_MB_(18.69%) using LeetCodeNet.Com_github_leetcode; +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ public class Solution { public ListNode AddTwoNumbers(ListNode l1, ListNode l2) { ListNode dummyHead = new ListNode(0); diff --git a/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs b/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs index dda6154..aacf6cd 100644 --- a/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs @@ -2,7 +2,8 @@ namespace LeetCodeNet.G0001_0100.S0003_longest_substring_without_repeating_chara // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window // #Algorithm_I_Day_6_Sliding_Window #Level_2_Day_14_Sliding_Window/Two_Pointer #Udemy_Strings -// #Big_O_Time_O(n)_Space_O(1) #2023_12_22_Time_50_ms_(98.40%)_Space_41.9_MB_(30.26%) +// #Top_Interview_150_Sliding_Window #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task +// #2025_06_12_Time_3_ms_(96.84%)_Space_44.64_MB_(30.11%) public class Solution { public int LengthOfLongestSubstring(string s) { diff --git a/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs b/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs index 1e89c21..b783391 100644 --- a/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs @@ -1,7 +1,8 @@ namespace LeetCodeNet.G0001_0100.S0004_median_of_two_sorted_arrays { // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer -// #Big_O_Time_O(log(min(N,M)))_Space_O(1) #2023_12_22_Time_83_ms_(96.35%)_Space_54_MB_(6.56%) +// #Top_Interview_150_Binary_Search #Big_O_Time_O(log(min(N,M)))_Space_O(1) +// #AI_can_be_used_to_solve_the_task #2025_06_12_Time_0_ms_(100.00%)_Space_55.92_MB_(53.97%) public class Solution { public double FindMedianSortedArrays(int[] nums1, int[] nums2) { diff --git a/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs b/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs index 5b47a40..50a25f5 100644 --- a/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs @@ -2,8 +2,8 @@ namespace LeetCodeNet.G0001_0100.S0005_longest_palindromic_substring { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming // #Data_Structure_II_Day_9_String #Algorithm_II_Day_14_Dynamic_Programming -// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Big_O_Time_O(n)_Space_O(n) -// #2023_12_22_Time_61_ms_(99.50%)_Space_40_MB_(56.86%) +// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Top_Interview_150_Multidimensional_DP +// #Big_O_Time_O(n)_Space_O(n) #2025_06_12_Time_7_ms_(95.82%)_Space_41.34_MB_(65.26%) public class Solution { public string LongestPalindrome(string s) { diff --git a/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs b/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs index 9ef5f99..21dd5be 100644 --- a/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs @@ -1,6 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0006_zigzag_conversion { -// #Medium #String #2023_12_22_Time_59_ms_(99.87%)_Space_45.1_MB_(74.68%) +// #Medium #String #Top_Interview_150_Array/String +// #2025_06_12_Time_3_ms_(95.39%)_Space_46.59_MB_(85.85%) using System.Text; diff --git a/LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs b/LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs index 9cf2ba0..4e48b2d 100644 --- a/LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs @@ -1,7 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0007_reverse_integer { // #Medium #Top_Interview_Questions #Math #Udemy_Integers -// #2023_12_22_Time_23_ms_(59.02%)_Space_26.3_MB_(99.19%) +// #2025_06_12_Time_14_ms_(99.26%)_Space_29.02_MB_(67.56%) public class Solution { public int Reverse(int x) { diff --git a/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/Solution.cs b/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/Solution.cs index 33aea84..aa4b5b1 100644 --- a/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/Solution.cs @@ -1,6 +1,6 @@ namespace LeetCodeNet.G0001_0100.S0008_string_to_integer_atoi { -// #Medium #Top_Interview_Questions #String #2023_12_22_Time_43_ms_(99.83%)_Space_39.7_MB_(23.14%) +// #Medium #Top_Interview_Questions #String #2025_06_12_Time_0_ms_(100.00%)_Space_41.82_MB_(46.21%) public class Solution { public int MyAtoi(string str) { diff --git a/LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs b/LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs index a515ae4..1f94749 100644 --- a/LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs @@ -1,6 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0009_palindrome_number { -// #Easy #Math #Udemy_Integers #2023_12_22_Time_42_ms_(34.61%)_Space_31_MB_(36.04%) +// #Easy #Math #Udemy_Integers #Top_Interview_150_Math +// #2025_06_12_Time_1_ms_(99.90%)_Space_34.74_MB_(67.61%) public class Solution { public bool IsPalindrome(int x) { diff --git a/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs b/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs index 9e197dd..1c67bf8 100644 --- a/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs @@ -1,8 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0010_regular_expression_matching { -// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming #Recursion -// #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n) -// #2023_12_22_Time_59_ms_(96.10%)_Space_40.5_MB_(47.63%) +// #Hard #Top_Interview_Questions #String #Dynamic_Programming #Recursion #Udemy_Dynamic_Programming +// #Big_O_Time_O(m*n)_Space_O(m*n) #2025_06_12_Time_1_ms_(99.81%)_Space_42.56_MB_(59.73%) public class Solution { private bool?[,] cache; diff --git a/LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs b/LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs index 127b49d..943b2f7 100644 --- a/LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs @@ -1,15 +1,14 @@ namespace LeetCodeNet.G0001_0100.S0011_container_with_most_water { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers -// #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1) -// #2023_12_26_Time_248_ms_(11.15%)_Space_62.1_MB_(5.59%) +// #LeetCode_75_Two_Pointers #Algorithm_II_Day_4_Two_Pointers #Top_Interview_150_Two_Pointers +// #Big_O_Time_O(n)_Space_O(1) #2025_06_12_Time_1_ms_(99.97%)_Space_63.66_MB_(17.36%) public class Solution { public int MaxArea(int[] height) { int maxArea = -1; int left = 0; int right = height.Length - 1; - while (left < right) { if (height[left] < height[right]) { maxArea = Math.Max(maxArea, height[left] * (right - left)); @@ -19,7 +18,6 @@ public int MaxArea(int[] height) { right--; } } - return maxArea; } } diff --git a/LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs b/LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs index 1c130d3..e792ff9 100644 --- a/LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs @@ -2,21 +2,19 @@ namespace LeetCodeNet.G0001_0100.S0015_3sum { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers // #Data_Structure_II_Day_1_Array #Algorithm_II_Day_3_Two_Pointers #Udemy_Two_Pointers -// #Big_O_Time_O(n*log(n))_Space_O(n^2) #2023_12_26_Time_173_ms_(75.85%)_Space_74.7_MB_(28.23%) +// #Top_Interview_150_Two_Pointers #Big_O_Time_O(n*log(n))_Space_O(n^2) +// #2025_06_12_Time_34_ms_(76.14%)_Space_66.14_MB_(37.36%) public class Solution { public IList> ThreeSum(int[] nums) { Array.Sort(nums); int len = nums.Length; IList> result = new List>(); - for (int i = 0; i < len - 2; i++) { int l = i + 1; int r = len - 1; - while (r > l) { int sum = nums[i] + nums[l] + nums[r]; - if (sum < 0) { l++; } else if (sum > 0) { @@ -24,25 +22,20 @@ public IList> ThreeSum(int[] nums) { } else { IList list = new List { nums[i], nums[l], nums[r] }; result.Add(list); - while (l < r && nums[l + 1] == nums[l]) { l++; } - while (r > l && nums[r - 1] == nums[r]) { r--; } - l++; r--; } } - while (i < len - 1 && nums[i + 1] == nums[i]) { i++; } } - return result; } } diff --git a/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs b/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs index ef64501..a2e6e7c 100644 --- a/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs @@ -1,8 +1,9 @@ namespace LeetCodeNet.G0001_0100.S0017_letter_combinations_of_a_phone_number { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking -// #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion -// #Big_O_Time_O(4^n)_Space_O(n) #2023_12_26_Time_108_ms_(95.24%)_Space_46.3_MB_(5.39%) +// #LeetCode_75_Backtracking #Algorithm_II_Day_11_Recursion_Backtracking +// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(4^n)_Space_O(n) +// #2025_06_12_Time_0_ms_(100.00%)_Space_48.12_MB_(16.34%) using System.Text; @@ -12,25 +13,25 @@ public IList LetterCombinations(string digits) { return new List(); } string[] letters = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; - IList ans = new List(); + List ans = new List(); StringBuilder sb = new StringBuilder(); FindCombinations(0, digits, letters, sb, ans); return ans; } private void FindCombinations( - int start, string nums, string[] letters, StringBuilder curr, IList ans) { + int start, string nums, string[] letters, StringBuilder curr, List ans) { if (curr.Length == nums.Length) { ans.Add(curr.ToString()); return; } for (int i = start; i < nums.Length; i++) { - int n = int.Parse(nums[i].ToString()); + int n = nums[i] - '0'; // Convert char to int for (int j = 0; j < letters[n].Length; j++) { char ch = letters[n][j]; curr.Append(ch); FindCombinations(i + 1, nums, letters, curr, ans); - curr.Length--; // Equivalent to deleting the last character in StringBuilder + curr.Remove(curr.Length - 1, 1); // Remove last character } } } diff --git a/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs b/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs index 2006618..955e100 100644 --- a/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs @@ -1,11 +1,22 @@ namespace LeetCodeNet.G0001_0100.S0019_remove_nth_node_from_end_of_list { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Two_Pointers #Linked_List -// #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Big_O_Time_O(L)_Space_O(L) -// #2023_12_26_Time_69_ms_(90.79%)_Space_40_MB_(5.04%) +// #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(L)_Space_O(L) #2025_06_12_Time_0_ms_(100.00%)_Space_42.68_MB_(23.67%) using LeetCodeNet.Com_github_leetcode; +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ public class Solution { private int n; @@ -22,7 +33,6 @@ private void RemoveNth(ListNode node) { } RemoveNth(node.next); this.n--; - if (this.n == 0) { node.next = node.next.next; } diff --git a/LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs b/LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs index d3b195e..8d2ef71 100644 --- a/LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs @@ -1,8 +1,8 @@ namespace LeetCodeNet.G0001_0100.S0020_valid_parentheses { // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Stack -// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Big_O_Time_O(n)_Space_O(n) -// #2023_12_26_Time_53_ms_(96.68%)_Space_39.3_MB_(10.78%) +// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Top_Interview_150_Stack +// #Big_O_Time_O(n)_Space_O(n) #2025_06_12_Time_2_ms_(82.01%)_Space_42.00_MB_(72.34%) using System; using System.Collections.Generic; diff --git a/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs b/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs index 2e98ffb..2b3d026 100644 --- a/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs @@ -2,16 +2,26 @@ namespace LeetCodeNet.G0001_0100.S0021_merge_two_sorted_lists { // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion // #Data_Structure_I_Day_7_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking -// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(m+n)_Space_O(m+n) -// #2023_12_26_Time_69_ms_(92.74%)_Space_41.4_MB_(5.11%) +// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(m+n)_Space_O(m+n) #2025_06_12_Time_0_ms_(100.00%)_Space_43.51_MB_(35.63%) using LeetCodeNet.Com_github_leetcode; +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ public class Solution { public ListNode MergeTwoLists(ListNode l1, ListNode l2) { ListNode list = new ListNode(-1); ListNode head = list; - while (l1 != null || l2 != null) { if (l1 != null && l2 != null) { if (l1.val <= l2.val) { @@ -30,7 +40,6 @@ public ListNode MergeTwoLists(ListNode l1, ListNode l2) { } list = list.next; } - return head.next; } } diff --git a/LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs b/LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs index 747aa77..b934bef 100644 --- a/LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs @@ -2,7 +2,8 @@ namespace LeetCodeNet.G0001_0100.S0022_generate_parentheses { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming // #Backtracking #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion -// #Big_O_Time_O(2^n)_Space_O(n) #2023_12_26_Time_81_ms_(99.57%)_Space_48.3_MB_(12.19%) +// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n) +// #2025_06_12_Time_0_ms_(100.00%)_Space_49.67_MB_(93.07%) using System.Collections.Generic; using System.Text; diff --git a/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs b/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs index a55de86..4c634c1 100644 --- a/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs @@ -1,11 +1,22 @@ namespace LeetCodeNet.G0001_0100.S0023_merge_k_sorted_lists { // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Heap_Priority_Queue #Linked_List -// #Divide_and_Conquer #Merge_Sort #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) -// #2023_12_26_Time_78_ms_(98.24%)_Space_45_MB_(13.27%) +// #Divide_and_Conquer #Merge_Sort #Top_Interview_150_Divide_and_Conquer +// #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) #2025_06_12_Time_3_ms_(97.54%)_Space_48.23_MB_(85.01%) using LeetCodeNet.Com_github_leetcode; +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ public class Solution { public ListNode MergeKLists(ListNode[] lists) { if (lists.Length == 0) { diff --git a/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs b/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs index 8905617..46411c6 100644 --- a/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs @@ -2,10 +2,21 @@ namespace LeetCodeNet.G0001_0100.S0024_swap_nodes_in_pairs { // #Medium #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_12_Linked_List // #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1) -// #2023_12_26_Time_58_ms_(98.51%)_Space_40_MB_(9.14%) +// #2025_06_12_Time_0_ms_(100.00%)_Space_41.28_MB_(72.95%) using LeetCodeNet.Com_github_leetcode; +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ public class Solution { public ListNode SwapPairs(ListNode head) { if (head == null) { diff --git a/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs b/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs index eedcb8a..997f9a0 100644 --- a/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs @@ -1,11 +1,22 @@ namespace LeetCodeNet.G0001_0100.S0025_reverse_nodes_in_k_group { // #Hard #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_13_Linked_List -// #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(k) -// #2023_12_26_Time_75_ms_(86.97%)_Space_43.9_MB_(5.81%) +// #Udemy_Linked_List #Top_Interview_150_Linked_List #Big_O_Time_O(n)_Space_O(k) +// #2025_06_12_Time_0_ms_(100.00%)_Space_46.05_MB_(68.15%) using LeetCodeNet.Com_github_leetcode; +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ public class Solution { public ListNode ReverseKGroup(ListNode head, int k) { if (head == null || head.next == null || k == 1) { diff --git a/LeetCodeNet/G0001_0100/S0031_next_permutation/Solution.cs b/LeetCodeNet/G0001_0100/S0031_next_permutation/Solution.cs index c899e0c..7a8f5e5 100644 --- a/LeetCodeNet/G0001_0100/S0031_next_permutation/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0031_next_permutation/Solution.cs @@ -1,7 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0031_next_permutation { // #Medium #Top_100_Liked_Questions #Array #Two_Pointers #Big_O_Time_O(n)_Space_O(1) -// #2023_12_28_Time_202_ms_(5.19%)_Space_46.2_MB_(5.39%) +// #2025_06_12_Time_0_ms_(100.00%)_Space_47.82_MB_(11.04%) public class Solution { public void NextPermutation(int[] nums) { diff --git a/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/Solution.cs b/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/Solution.cs index 1c4ce1c..bd09d50 100644 --- a/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/Solution.cs @@ -1,7 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0032_longest_valid_parentheses { // #Hard #Top_100_Liked_Questions #String #Dynamic_Programming #Stack #Big_O_Time_O(n)_Space_O(1) -// #2023_12_28_Time_49_ms_(96.18%)_Space_38.5_MB_(13.54%) +// #2025_06_12_Time_2_ms_(94.56%)_Space_40.52_MB_(91.98%) public class Solution { public int LongestValidParentheses(string s) { diff --git a/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs b/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs index e01fcd3..7138561 100644 --- a/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs @@ -2,8 +2,8 @@ namespace LeetCodeNet.G0001_0100.S0033_search_in_rotated_sorted_array { // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search // #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_11 #Level_2_Day_8_Binary_Search -// #Udemy_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) -// #2023_12_28_Time_63_ms_(96.89%)_Space_41.1_MB_(5.40%) +// #Udemy_Binary_Search #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) +// #2025_06_12_Time_0_ms_(100.00%)_Space_42.66_MB_(42.72%) public class Solution { public int Search(int[] nums, int target) { diff --git a/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/Solution.cs b/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/Solution.cs index eeafd8a..7c510ec 100644 --- a/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/Solution.cs @@ -1,8 +1,8 @@ namespace 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 -// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Big_O_Time_O(log_n)_Space_O(1) -// #2023_12_28_Time_171_ms_(5.87%)_Space_48.4_MB_(5.63%) +// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Top_Interview_150_Binary_Search +// #Big_O_Time_O(log_n)_Space_O(1) #2025_06_12_Time_0_ms_(100.00%)_Space_49.94_MB_(35.02%) public class Solution { public int[] SearchRange(int[] nums, int target) { diff --git a/LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs b/LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs index 2581a6b..76f85f2 100644 --- a/LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs @@ -1,8 +1,8 @@ namespace LeetCodeNet.G0001_0100.S0035_search_insert_position { // #Easy #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_I_Day_1_Binary_Search -// #Binary_Search_I_Day_2 #Big_O_Time_O(log_n)_Space_O(1) -// #2023_12_28_Time_106_ms_(6.17%)_Space_42_MB_(5.47%) +// #Binary_Search_I_Day_2 #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) +// #2025_06_12_Time_0_ms_(100.00%)_Space_43.13_MB_(61.70%) public class Solution { public int SearchInsert(int[] nums, int target) { diff --git a/LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs b/LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs index 5bf883d..f616f48 100644 --- a/LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs @@ -2,7 +2,8 @@ namespace LeetCodeNet.G0001_0100.S0039_combination_sum { // #Medium #Top_100_Liked_Questions #Array #Backtracking #Algorithm_II_Day_10_Recursion_Backtracking // #Level_2_Day_20_Brute_Force/Backtracking #Udemy_Backtracking/Recursion -// #Big_O_Time_O(2^n)_Space_O(n+2^n) #2023_12_28_Time_94_ms_(99.60%)_Space_46.5_MB_(23.61%) +// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n+2^n) +// #2025_06_12_Time_1_ms_(100.00%)_Space_48.21_MB_(42.68%) using System.Collections.Generic; diff --git a/LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs b/LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs index 9e29a86..c9c61af 100644 --- a/LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs @@ -1,7 +1,7 @@ namespace LeetCodeNet.G0001_0100.S0041_first_missing_positive { // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Udemy_Arrays -// #Big_O_Time_O(n)_Space_O(n) #2023_12_28_Time_192_ms_(13.98%)_Space_57.8_MB_(13.98%) +// #Big_O_Time_O(n)_Space_O(n) #2024_01_11_Time_178_ms_(36.64%)_Space_57.6_MB_(32.67%) public class Solution { public int FirstMissingPositive(int[] nums) { diff --git a/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs b/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs index 6a75842..83e5766 100644 --- a/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs @@ -2,7 +2,8 @@ namespace 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) #2023_12_28_Time_81_ms_(89.96%)_Space_44.5_MB_(13.62%) +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2023_12_28_Time_81_ms_(89.96%)_Space_44.5_MB_(13.62%) public class Solution { public int Trap(int[] height) { diff --git a/LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs b/LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs index bec8eed..e0ef051 100644 --- a/LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs @@ -2,7 +2,8 @@ namespace 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) #2023_12_28_Time_144_ms_(15.35%)_Space_44_MB_(16.51%) +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2024_01_11_Time_85_ms_(88.80%)_Space_44.1_MB_(33.81%) public class Solution { public int Jump(int[] nums) { diff --git a/LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs b/LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs index 21781ee..375d15d 100644 --- a/LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs +++ b/LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs @@ -2,8 +2,8 @@ namespace 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!) -// #2023_12_28_Time_148_ms_(5.56%)_Space_45.8_MB_(8.50%) +// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(n*n!)_Space_O(n+n!) +// #2024_01_11_Time_96_ms_(96.56%)_Space_46.4_MB_(12.40%) using System.Collections.Generic; diff --git a/LeetCodeNet/G0001_0100/S0048_rotate_image/Solution.cs b/LeetCodeNet/G0001_0100/S0048_rotate_image/Solution.cs new file mode 100644 index 0000000..a4e0afd --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0048_rotate_image/Solution.cs @@ -0,0 +1,24 @@ +namespace 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 +// #Top_Interview_150_Matrix #Big_O_Time_O(n^2)_Space_O(1) +// #2024_01_04_Time_92_ms_(97.78%)_Space_45.7_MB_(9.23%) + +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]); + } + } + } +} +} 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..7441873 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0048_rotate_image/readme.md @@ -0,0 +1,42 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0049_group_anagrams/Solution.cs b/LeetCodeNet/G0001_0100/S0049_group_anagrams/Solution.cs new file mode 100644 index 0000000..9443eab --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0049_group_anagrams/Solution.cs @@ -0,0 +1,26 @@ +namespace 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 +// #Top_Interview_150_Hashmap #Big_O_Time_O(n*k_log_k)_Space_O(n) +// #2024_01_04_Time_145_ms_(96.20%)_Space_80.2_MB_(38.80%) + +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(); + } +} +} 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..c1641ce --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0049_group_anagrams/readme.md @@ -0,0 +1,31 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0051_n_queens/Solution.cs b/LeetCodeNet/G0001_0100/S0051_n_queens/Solution.cs new file mode 100644 index 0000000..c6f6764 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0051_n_queens/Solution.cs @@ -0,0 +1,34 @@ +namespace LeetCodeNet.G0001_0100.S0051_n_queens { + +// #Hard #Top_100_Liked_Questions #Array #Backtracking #Big_O_Time_O(N!)_Space_O(N) +// #2024_01_04_Time_106_ms_(96.34%)_Space_54.6_MB_(5.79%) + +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; + } + } + } +} +} 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..4227951 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0051_n_queens/readme.md @@ -0,0 +1,29 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs b/LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs new file mode 100644 index 0000000..e46fa4b --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0001_0100.S0053_maximum_subarray { + +// #Medium #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 #Top_Interview_150_Kadane's_Algorithm #Big_O_Time_O(n)_Space_O(1) +// #2024_01_11_Time_270_ms_(38.35%)_Space_62.7_MB_(7.88%) + +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; + } +} +} 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..521093b --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0053_maximum_subarray/readme.md @@ -0,0 +1,34 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs b/LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs new file mode 100644 index 0000000..e889f80 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs @@ -0,0 +1,23 @@ +namespace 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 +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2024_01_04_Time_189_ms_(38.02%)_Space_61.6_MB_(81.87%) + +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; + } +} +} 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..0f4d2db --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0055_jump_game/readme.md @@ -0,0 +1,28 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0056_merge_intervals/Solution.cs b/LeetCodeNet/G0001_0100/S0056_merge_intervals/Solution.cs new file mode 100644 index 0000000..84d0cf0 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0056_merge_intervals/Solution.cs @@ -0,0 +1,21 @@ +namespace 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 +// #Top_Interview_150_Intervals #Big_O_Time_O(n_log_n)_Space_O(n) +// #2024_01_05_Time_149_ms_(89.48%)_Space_55.6_MB_(11.71%) + +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(); + } +} +} 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..d4409db --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0056_merge_intervals/readme.md @@ -0,0 +1,27 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0062_unique_paths/Solution.cs b/LeetCodeNet/G0001_0100/S0062_unique_paths/Solution.cs new file mode 100644 index 0000000..7cb0e8f --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0062_unique_paths/Solution.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0001_0100.S0062_unique_paths { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math +// #Combinatorics #LeetCode_75_DP/Multidimensional #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) #2024_01_05_Time_16_ms_(93.42%)_Space_26.2_MB_(96.08%) + +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]; + } +} +} 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..eaf4311 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0062_unique_paths/readme.md @@ -0,0 +1,47 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/Solution.cs b/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/Solution.cs new file mode 100644 index 0000000..76af10a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/Solution.cs @@ -0,0 +1,25 @@ +namespace LeetCodeNet.G0001_0100.S0064_minimum_path_sum { + +// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix +// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP +// #Big_O_Time_O(m*n)_Space_O(m*n) #2024_01_05_Time_74_ms_(94.37%)_Space_42.6_MB_(18.50%) + +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]; + } +} +} 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..fa60cb1 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0064_minimum_path_sum/readme.md @@ -0,0 +1,30 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs b/LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs new file mode 100644 index 0000000..2c67138 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs @@ -0,0 +1,23 @@ +namespace 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 #Top_Interview_150_1D_DP +// #Big_O_Time_O(n)_Space_O(n) #2024_01_05_Time_15_ms_(94.90%)_Space_26.2_MB_(96.48%) + +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]; + } +} +} 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..41c3a2a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0070_climbing_stairs/readme.md @@ -0,0 +1,27 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs b/LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs new file mode 100644 index 0000000..8ff5488 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs @@ -0,0 +1,27 @@ +namespace LeetCodeNet.G0001_0100.S0072_edit_distance { + +// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #LeetCode_75_DP/Multidimensional +// #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_19 +// #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(n^2)_Space_O(n2) +// #2024_01_05_Time_51_ms_(95.38%)_Space_44.5_MB_(20.65%) + +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]; + } +} +} 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..fbd054c --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0072_edit_distance/readme.md @@ -0,0 +1,32 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/Solution.cs b/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/Solution.cs new file mode 100644 index 0000000..059360b --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/Solution.cs @@ -0,0 +1,60 @@ +namespace LeetCodeNet.G0001_0100.S0073_set_matrix_zeroes { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Matrix +// #Udemy_2D_Arrays/Matrix #Top_Interview_150_Matrix #Big_O_Time_O(m*n)_Space_O(1) +// #2024_01_05_Time_124_ms_(96.92%)_Space_52_MB_(9.38%) + +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; + } + } + } +} +} 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..404b556 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/readme.md @@ -0,0 +1,36 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs b/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs new file mode 100644 index 0000000..21ce44a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs @@ -0,0 +1,29 @@ +namespace 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 #Top_Interview_150_Binary_Search #Big_O_Time_O(endRow+endCol)_Space_O(1) +// #2024_01_05_Time_76_ms_(90.98%)_Space_43.2_MB_(9.93%) + +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; + } +} +} 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..ce4e033 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/readme.md @@ -0,0 +1,31 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0075_sort_colors/Solution.cs b/LeetCodeNet/G0001_0100/S0075_sort_colors/Solution.cs new file mode 100644 index 0000000..773d679 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0075_sort_colors/Solution.cs @@ -0,0 +1,26 @@ +namespace 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) +// #2024_01_05_Time_98_ms_(93.59%)_Space_45.3_MB_(5.46%) + +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; + } + } +} +} 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..4062c6f --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0075_sort_colors/readme.md @@ -0,0 +1,41 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/Solution.cs b/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/Solution.cs new file mode 100644 index 0000000..1e30a5e --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/Solution.cs @@ -0,0 +1,35 @@ +namespace 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 #Top_Interview_150_Sliding_Window +// #Big_O_Time_O(s.length())_Space_O(1) #2024_01_05_Time_56_ms_(98.72%)_Space_42.6_MB_(42.02%) + +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); + } +} +} 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..7c7d492 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0076_minimum_window_substring/readme.md @@ -0,0 +1,42 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0078_subsets/Solution.cs b/LeetCodeNet/G0001_0100/S0078_subsets/Solution.cs new file mode 100644 index 0000000..8238297 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0078_subsets/Solution.cs @@ -0,0 +1,25 @@ +namespace 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) #2024_01_05_Time_101_ms_(94.29%)_Space_45.7_MB_(8.93%) + +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); + } + } +} +} diff --git a/LeetCodeNet/G0001_0100/S0078_subsets/readme.md b/LeetCodeNet/G0001_0100/S0078_subsets/readme.md new file mode 100644 index 0000000..2bd42ee --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0078_subsets/readme.md @@ -0,0 +1,25 @@ +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**. \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0079_word_search/Solution.cs b/LeetCodeNet/G0001_0100/S0079_word_search/Solution.cs new file mode 100644 index 0000000..bfc4103 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0079_word_search/Solution.cs @@ -0,0 +1,46 @@ +namespace LeetCodeNet.G0001_0100.S0079_word_search { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Backtracking +// #Algorithm_II_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking +// #Big_O_Time_O(4^(m*n))_Space_O(m*n) #2024_01_05_Time_152_ms_(99.69%)_Space_42.3_MB_(26.96%) + +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; + } +} +} 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..0500297 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0079_word_search/readme.md @@ -0,0 +1,41 @@ +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`? \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/Solution.cs b/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/Solution.cs new file mode 100644 index 0000000..b94e23d --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/Solution.cs @@ -0,0 +1,26 @@ +namespace 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) #2024_01_08_Time_304_ms_(30.92%)_Space_52.4_MB_(29.92%) + +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; + } +} +} 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..96ca2d0 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0084_largest_rectangle_in_histogram/readme.md @@ -0,0 +1,28 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/Solution.cs b/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/Solution.cs new file mode 100644 index 0000000..9a82934 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/Solution.cs @@ -0,0 +1,45 @@ +namespace 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) +// #2024_01_08_Time_90_ms_(99.30%)_Space_45.5_MB_(6.37%) + +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); + } + } +} +} 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..5068d01 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/readme.md @@ -0,0 +1,48 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/Solution.cs b/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/Solution.cs new file mode 100644 index 0000000..12568a8 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/Solution.cs @@ -0,0 +1,18 @@ +namespace LeetCodeNet.G0001_0100.S0096_unique_binary_search_trees { + +// #Medium #Dynamic_Programming #Math #Tree #Binary_Tree #Binary_Search_Tree +// #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1) +// #2024_01_08_Time_13_ms_(98.48%)_Space_26.2_MB_(88.64%) + +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; + } +} +} 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..de6a286 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/readme.md @@ -0,0 +1,23 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs b/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs new file mode 100644 index 0000000..822cba9 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs @@ -0,0 +1,39 @@ +namespace 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 #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(N)_Space_O(log(N)) +// #2024_01_08_Time_75_ms_(97.31%)_Space_45.3_MB_(19.73%) + +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); + } +} +} 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..a65734a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/readme.md @@ -0,0 +1,34 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0101_symmetric_tree/Solution.cs b/LeetCodeNet/G0101_0200/S0101_symmetric_tree/Solution.cs new file mode 100644 index 0000000..03cdd86 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0101_symmetric_tree/Solution.cs @@ -0,0 +1,41 @@ +namespace 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 +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(log(N)) +// #2024_01_08_Time_64_ms_(97.79%)_Space_42.9_MB_(23.56%) + +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); + } +} +} 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..bd97864 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0101_symmetric_tree/readme.md @@ -0,0 +1,28 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs b/LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs new file mode 100644 index 0000000..6539c46 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs @@ -0,0 +1,54 @@ +namespace LeetCodeNet.G0101_0200.S0102_binary_tree_level_order_traversal { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Breadth_First_Search #Tree +// #Binary_Tree #Data_Structure_I_Day_11_Tree #Level_1_Day_6_Tree #Udemy_Tree_Stack_Queue +// #Top_Interview_150_Binary_Tree_BFS #Big_O_Time_O(N)_Space_O(N) +// #2024_01_09_Time_97_ms_(98.14%)_Space_47.4_MB_(12.94%) + +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> LevelOrder(TreeNode root) { + IList> result = new List>(); + if (root == null) { + return result; + } + Queue queue = new Queue(); + queue.Enqueue(root); + queue.Enqueue(null); + List level = new List(); + while (queue.Count > 0) { + root = queue.Dequeue(); + while (queue.Count > 0 && root != null) { + level.Add((int)root.val); + if (root.left != null) { + queue.Enqueue(root.left); + } + if (root.right != null) { + queue.Enqueue(root.right); + } + root = queue.Dequeue(); + } + result.Add(level); + level = new List(); + if (queue.Count > 0) { + queue.Enqueue(null); + } + } + return result; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/readme.md b/LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/readme.md new file mode 100644 index 0000000..92fe4a4 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/readme.md @@ -0,0 +1,30 @@ +102\. Binary Tree Level Order Traversal + +Medium + +Given the `root` of a binary tree, return _the level order traversal of its nodes' values_. (i.e., from left to right, level by level). + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg) + +**Input:** root = [3,9,20,null,null,15,7] + +**Output:** [[3],[9,20],[15,7]] + +**Example 2:** + +**Input:** root = [1] + +**Output:** [[1]] + +**Example 3:** + +**Input:** root = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 2000]`. +* `-1000 <= Node.val <= 1000` \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs b/LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs new file mode 100644 index 0000000..6e665f7 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs @@ -0,0 +1,38 @@ +namespace LeetCodeNet.G0101_0200.S0104_maximum_depth_of_binary_tree { + +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search +// #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS #Data_Structure_I_Day_11_Tree +// #Programming_Skills_I_Day_10_Linked_List_and_Tree #Udemy_Tree_Stack_Queue +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(H) +// #2024_01_09_Time_65_ms_(93.31%)_Space_42.3_MB_(9.74%) + +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 int MaxDepth(TreeNode root) { + return FindDepth(root, 0); + } + + private int FindDepth(TreeNode node, int currentDepth) { + if (node == null) { + return 0; + } + currentDepth++; + return 1 + + Math.Max(FindDepth(node.left, currentDepth), FindDepth(node.right, currentDepth)); + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/readme.md b/LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/readme.md new file mode 100644 index 0000000..052ac01 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/readme.md @@ -0,0 +1,38 @@ +104\. Maximum Depth of Binary Tree + +Easy + +Given the `root` of a binary tree, return _its maximum depth_. + +A binary tree's **maximum depth** is the number of nodes along the longest path from the root node down to the farthest leaf node. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg) + +**Input:** root = [3,9,20,null,null,15,7] + +**Output:** 3 + +**Example 2:** + +**Input:** root = [1,null,2] + +**Output:** 2 + +**Example 3:** + +**Input:** root = [] + +**Output:** 0 + +**Example 4:** + +**Input:** root = [0] + +**Output:** 1 + +**Constraints:** + +* The number of nodes in the tree is in the range [0, 104]. +* `-100 <= Node.val <= 100` \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.cs b/LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.cs new file mode 100644 index 0000000..f9c4f78 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.cs @@ -0,0 +1,50 @@ +namespace LeetCodeNet.G0101_0200.S0105_construct_binary_tree_from_preorder_and_inorder_traversal { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Tree #Binary_Tree +// #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Top_Interview_150_Binary_Tree_General +// #Big_O_Time_O(N)_Space_O(N) #2024_01_09_Time_53_ms_(99.83%)_Space_42.5_MB_(46.06%) + +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 j; + private Dictionary map = new Dictionary(); + + public int Get(int key) { + return map[key]; + } + + private TreeNode Answer(int[] preorder, int[] inorder, int start, int end) { + if (start > end || j > preorder.Length) { + return null; + } + int value = preorder[j++]; + int index = Get(value); + TreeNode node = new TreeNode(value); + node.left = Answer(preorder, inorder, start, index - 1); + node.right = Answer(preorder, inorder, index + 1, end); + return node; + } + + public TreeNode BuildTree(int[] preorder, int[] inorder) { + j = 0; + for (int i = 0; i < preorder.Length; i++) { + map.Add(inorder[i], i); + } + return Answer(preorder, inorder, 0, preorder.Length - 1); + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md b/LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md new file mode 100644 index 0000000..fa4a8b4 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md @@ -0,0 +1,29 @@ +105\. Construct Binary Tree from Preorder and Inorder Traversal + +Medium + +Given two integer arrays `preorder` and `inorder` where `preorder` is the preorder traversal of a binary tree and `inorder` is the inorder traversal of the same tree, construct and return _the binary tree_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/tree.jpg) + +**Input:** preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] + +**Output:** [3,9,20,null,null,15,7] + +**Example 2:** + +**Input:** preorder = [-1], inorder = [-1] + +**Output:** [-1] + +**Constraints:** + +* `1 <= preorder.length <= 3000` +* `inorder.length == preorder.length` +* `-3000 <= preorder[i], inorder[i] <= 3000` +* `preorder` and `inorder` consist of **unique** values. +* Each value of `inorder` also appears in `preorder`. +* `preorder` is **guaranteed** to be the preorder traversal of the tree. +* `inorder` is **guaranteed** to be the inorder traversal of the tree. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/Solution.cs b/LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/Solution.cs new file mode 100644 index 0000000..6284c40 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/Solution.cs @@ -0,0 +1,51 @@ +namespace LeetCodeNet.G0101_0200.S0114_flatten_binary_tree_to_linked_list { + +// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Stack #Linked_List +// #Udemy_Linked_List #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(N) +// #2024_01_09_Time_52_ms_(98.71%)_Space_41.3_MB_(6.68%) + +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 void Flatten(TreeNode root) { + if (root != null) { + FindTail(root); + } + } + + private TreeNode FindTail(TreeNode root) { + TreeNode left = root.left; + TreeNode right = root.right; + TreeNode tail; + // find the tail of left subtree, tail means the most left leaf + if (left != null) { + tail = FindTail(left); + // stitch the right subtree below the tail + root.left = null; + root.right = left; + tail.right = right; + } else { + tail = root; + } + // find tail of the right subtree + if (tail.right == null) { + return tail; + } else { + return FindTail(tail.right); + } + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/readme.md b/LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/readme.md new file mode 100644 index 0000000..ea101ac --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/readme.md @@ -0,0 +1,35 @@ +114\. Flatten Binary Tree to Linked List + +Medium + +Given the `root` of a binary tree, flatten the tree into a "linked list": + +* The "linked list" should use the same `TreeNode` class where the `right` child pointer points to the next node in the list and the `left` child pointer is always `null`. +* The "linked list" should be in the same order as a [**pre-order** **traversal**](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR) of the binary tree. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/14/flaten.jpg) + +**Input:** root = [1,2,5,3,4,null,6] + +**Output:** [1,null,2,null,3,null,4,null,5,null,6] + +**Example 2:** + +**Input:** root = [] + +**Output:** [] + +**Example 3:** + +**Input:** root = [0] + +**Output:** [0] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 2000]`. +* `-100 <= Node.val <= 100` + +**Follow up:** Can you flatten the tree in-place (with `O(1)` extra space)? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs b/LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs new file mode 100644 index 0000000..2c3d700 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs @@ -0,0 +1,24 @@ +namespace LeetCodeNet.G0101_0200.S0121_best_time_to_buy_and_sell_stock { + +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming +// #Data_Structure_I_Day_3_Array #Dynamic_Programming_I_Day_7 #Level_1_Day_5_Greedy #Udemy_Arrays +// #Top_Interview_150_Array/String #Big_O_Time_O(N)_Space_O(1) +// #2024_01_09_Time_328_ms_(35.43%)_Space_58.2_MB_(5.29%) + +public class Solution { + public int MaxProfit(int[] prices) { + int min = int.MaxValue; + int profit = 0; + int max = 0; + for (int i = 0; i < prices.Length; i++) { + if (prices[i] < min) { + min = prices[i]; + } + profit = prices[i] - min; + max = Math.Max(profit, max); + + } + return max; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/readme.md b/LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/readme.md new file mode 100644 index 0000000..6e22ccf --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/readme.md @@ -0,0 +1,30 @@ +121\. Best Time to Buy and Sell Stock + +Easy + +You are given an array `prices` where `prices[i]` is the price of a given stock on the `ith` day. + +You want to maximize your profit by choosing a **single day** to buy one stock and choosing a **different day in the future** to sell that stock. + +Return _the maximum profit you can achieve from this transaction_. If you cannot achieve any profit, return `0`. + +**Example 1:** + +**Input:** prices = [7,1,5,3,6,4] + +**Output:** 5 + +**Explanation:** Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell. + +**Example 2:** + +**Input:** prices = [7,6,4,3,1] + +**Output:** 0 + +**Explanation:** In this case, no transactions are done and the max profit = 0. + +**Constraints:** + +* 1 <= prices.length <= 105 +* 0 <= prices[i] <= 104 \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/Solution.cs b/LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/Solution.cs new file mode 100644 index 0000000..ba851f7 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/Solution.cs @@ -0,0 +1,44 @@ +namespace LeetCodeNet.G0101_0200.S0124_binary_tree_maximum_path_sum { + +// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search +// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General +// #Big_O_Time_O(N)_Space_O(N) #2024_01_09_Time_85_ms_(91.69%)_Space_47.6_MB_(23.52%) + +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 max = int.MinValue; + + private int Helper(TreeNode root) { + if (root == null) { + return 0; + } + // to avoid the -ve values in left side we will compare them with 0 + int left = Math.Max(0, Helper(root.left)); + int right = Math.Max(0, Helper(root.right)); + int current = (int)(root.val + left + right); + if (current > max) { + max = current; + } + return (int)(root.val + Math.Max(left, right)); + } + + public int MaxPathSum(TreeNode root) { + Helper(root); + return max; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/readme.md b/LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/readme.md new file mode 100644 index 0000000..29f9180 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/readme.md @@ -0,0 +1,34 @@ +124\. Binary Tree Maximum Path Sum + +Hard + +A **path** in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence **at most once**. Note that the path does not need to pass through the root. + +The **path sum** of a path is the sum of the node's values in the path. + +Given the `root` of a binary tree, return _the maximum **path sum** of any **non-empty** path_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/13/exx1.jpg) + +**Input:** root = [1,2,3] + +**Output:** 6 + +**Explanation:** The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/10/13/exx2.jpg) + +**Input:** root = [-10,9,20,null,null,15,7] + +**Output:** 42 + +**Explanation:** The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42. + +**Constraints:** + +* The number of nodes in the tree is in the range [1, 3 * 104]. +* `-1000 <= Node.val <= 1000` \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/Solution.cs b/LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/Solution.cs new file mode 100644 index 0000000..4856051 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/Solution.cs @@ -0,0 +1,30 @@ +namespace LeetCodeNet.G0101_0200.S0128_longest_consecutive_sequence { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find +// #Top_Interview_150_Hashmap #Big_O_Time_O(N_log_N)_Space_O(1) +// #2024_01_09_Time_201_ms_(61.50%)_Space_61.2_MB_(52.89%) + +public class Solution { + public int LongestConsecutive(int[] nums) { + if (nums.Length == 0) { + return 0; + } + Array.Sort(nums); + int max = int.MinValue; + int thsMax = 1; + for (int i = 0; i < nums.Length - 1; i++) { + if (nums[i + 1] == nums[i] + 1) { + thsMax += 1; + continue; + } + if (nums[i + 1] == nums[i]) { + continue; + } + // Start of a new Sequene + max = Math.Max(max, thsMax); + thsMax = 1; + } + return Math.Max(max, thsMax); + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/readme.md b/LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/readme.md new file mode 100644 index 0000000..b516939 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/readme.md @@ -0,0 +1,26 @@ +128\. Longest Consecutive Sequence + +Medium + +Given an unsorted array of integers `nums`, return _the length of the longest consecutive elements sequence._ + +You must write an algorithm that runs in `O(n)` time. + +**Example 1:** + +**Input:** nums = [100,4,200,1,3,2] + +**Output:** 4 + +**Explanation:** The longest consecutive elements sequence is `[1, 2, 3, 4]`. Therefore its length is 4. + +**Example 2:** + +**Input:** nums = [0,3,7,2,5,8,4,6,0,1] + +**Output:** 9 + +**Constraints:** + +* 0 <= nums.length <= 105 +* -109 <= nums[i] <= 109 \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/Solution.cs b/LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/Solution.cs new file mode 100644 index 0000000..dcf5a13 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/Solution.cs @@ -0,0 +1,36 @@ +namespace LeetCodeNet.G0101_0200.S0131_palindrome_partitioning { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming +// #Backtracking #Big_O_Time_O(N*2^N)_Space_O(2^N*N) +// #2024_01_09_Time_677_ms_(38.30%)_Space_148_MB_(5.53%) + +public class Solution { + public IList> Partition(string s) { + IList> res = new List>(); + Backtracking(res, new List(), s, 0); + return res; + } + + private void Backtracking(IList> res, IList currArr, string s, int start) { + if (start == s.Length) { + res.Add(new List(currArr)); + } + for (int end = start; end < s.Length; end++) { + if (!IsPanlindrome(s, start, end)) { + continue; + } + currArr.Add(s.Substring(start, end - start + 1)); + Backtracking(res, currArr, s, end + 1); + currArr.RemoveAt(currArr.Count - 1); + } + } + + private bool IsPanlindrome(string s, int start, int end) { + while (start < end && s[start] == s[end]) { + start++; + end--; + } + return start >= end; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/readme.md b/LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/readme.md new file mode 100644 index 0000000..450d879 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/readme.md @@ -0,0 +1,24 @@ +131\. Palindrome Partitioning + +Medium + +Given a string `s`, partition `s` such that every substring of the partition is a **palindrome**. Return all possible palindrome partitioning of `s`. + +A **palindrome** string is a string that reads the same backward as forward. + +**Example 1:** + +**Input:** s = "aab" + +**Output:** [["a","a","b"],["aa","b"]] + +**Example 2:** + +**Input:** s = "a" + +**Output:** [["a"]] + +**Constraints:** + +* `1 <= s.length <= 16` +* `s` contains only lowercase English letters. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs b/LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs new file mode 100644 index 0000000..15ed868 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs @@ -0,0 +1,17 @@ +namespace LeetCodeNet.G0101_0200.S0136_single_number { + +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation +// #LeetCode_75_Bit_Manipulation #Data_Structure_II_Day_1_Array +// #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers #Top_Interview_150_Bit_Manipulation +// #Big_O_Time_O(N)_Space_O(1) #2024_01_09_Time_87_ms_(93.37%)_Space_45.1_MB_(38.04%) + +public class Solution { + public int SingleNumber(int[] nums) { + int res = 0; + foreach (int num in nums) { + res ^= num; + } + return res; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0136_single_number/readme.md b/LeetCodeNet/G0101_0200/S0136_single_number/readme.md new file mode 100644 index 0000000..5f9d3df --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0136_single_number/readme.md @@ -0,0 +1,31 @@ +136\. Single Number + +Easy + +Given a **non-empty** array of integers `nums`, every element appears _twice_ except for one. Find that single one. + +You must implement a solution with a linear runtime complexity and use only constant extra space. + +**Example 1:** + +**Input:** nums = [2,2,1] + +**Output:** 1 + +**Example 2:** + +**Input:** nums = [4,1,2,1,2] + +**Output:** 4 + +**Example 3:** + +**Input:** nums = [1] + +**Output:** 1 + +**Constraints:** + +* 1 <= nums.length <= 3 * 104 +* -3 * 104 <= nums[i] <= 3 * 104 +* Each element in the array appears twice except for one element which appears only once. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs b/LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs new file mode 100644 index 0000000..d7e7634 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs @@ -0,0 +1,70 @@ +namespace LeetCodeNet.G0101_0200.S0138_copy_list_with_random_pointer { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Linked_List +// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(N)_Space_O(N) #2024_01_09_Time_59_ms_(96.51%)_Space_41.4_MB_(18.90%) + +using LeetCodeNet.Com_github_leetcode; + +/* +// Definition for a Node. +public class Node { + public int val; + public Node next; + public Node random; + + public Node(int _val) { + val = _val; + next = null; + random = null; + } +} +*/ +public class Solution { + public Node CopyRandomList(Node head) { + if (head == null) { + return null; + } + // first pass to have a clone node point to the next node. ie A->B becomes A->clonedNode->B + Node curr = head; + while (curr != null) { + Node clonedNode = new Node(curr.val); + clonedNode.next = curr.next; + curr.next = clonedNode; + curr = clonedNode.next; + } + curr = head; + // second pass to make the cloned node's random pointer point to the orginal node's randome + // pointer. + // ie. A's random pointer becomes ClonedNode's random pointer + while (curr != null) { + if (curr.random != null) { + curr.next.random = curr.random.next; + } else { + curr.next.random = null; + } + curr = curr.next.next; + } + curr = head; + // third pass to restore the links and return the head of the cloned nodes' list. + Node newHead = null; + while (curr != null) { + Node clonedNode; + if (newHead == null) { + clonedNode = curr.next; + newHead = clonedNode; + } else { + clonedNode = curr.next; + } + curr.next = clonedNode.next; + if (curr.next != null) { + clonedNode.next = curr.next.next; + } else { + clonedNode.next = null; + } + curr = curr.next; + } + return newHead; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/readme.md b/LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/readme.md new file mode 100644 index 0000000..9e2f939 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/readme.md @@ -0,0 +1,56 @@ +138\. Copy List with Random Pointer + +Medium + +A linked list of length `n` is given such that each node contains an additional random pointer, which could point to any node in the list, or `null`. + +Construct a [**deep copy**](https://en.wikipedia.org/wiki/Object_copying#Deep_copy) of the list. The deep copy should consist of exactly `n` **brand new** nodes, where each new node has its value set to the value of its corresponding original node. Both the `next` and `random` pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. **None of the pointers in the new list should point to nodes in the original list**. + +For example, if there are two nodes `X` and `Y` in the original list, where `X.random --> Y`, then for the corresponding two nodes `x` and `y` in the copied list, `x.random --> y`. + +Return _the head of the copied linked list_. + +The linked list is represented in the input/output as a list of `n` nodes. Each node is represented as a pair of `[val, random_index]` where: + +* `val`: an integer representing `Node.val` +* `random_index`: the index of the node (range from `0` to `n-1`) that the `random` pointer points to, or `null` if it does not point to any node. + +Your code will **only** be given the `head` of the original linked list. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2019/12/18/e1.png) + +**Input:** head = [[7,null],[13,0],[11,4],[10,2],[1,0]] + +**Output:** [[7,null],[13,0],[11,4],[10,2],[1,0]] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2019/12/18/e2.png) + +**Input:** head = [[1,1],[2,1]] + +**Output:** [[1,1],[2,1]] + +**Example 3:** + +**![](https://assets.leetcode.com/uploads/2019/12/18/e3.png)** + +**Input:** head = [[3,null],[3,0],[3,null]] + +**Output:** [[3,null],[3,0],[3,null]] + +**Example 4:** + +**Input:** head = [] + +**Output:** [] + +**Explanation:** The given linked list is empty (null pointer), so return null. + +**Constraints:** + +* `0 <= n <= 1000` +* `-10000 <= Node.val <= 10000` +* `Node.random` is `null` or is pointing to some node in the linked list. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs b/LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs new file mode 100644 index 0000000..01bf806 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs @@ -0,0 +1,34 @@ +namespace LeetCodeNet.G0101_0200.S0139_word_break { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table +// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming +// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP +// #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2024_01_09_Time_64_ms_(98.44%)_Space_49.2_MB_(10.24%) + +public class Solution { + private Dictionary visited = new(); + private HashSet? set; + + public bool WordBreak(string s, IList wordDict) { + set = new HashSet(wordDict); + return CheckWordBreak(s); + } + + public bool CheckWordBreak(string s) { + if (visited.ContainsKey(s)) { + return visited[s]; + } + if (set.Contains(s)) { + return true; + } + for (int i=0; i[0, 104]. +* -105 <= Node.val <= 105 +* `pos` is `-1` or a **valid index** in the linked-list. + +**Follow up:** Can you solve it using `O(1)` (i.e. constant) memory? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs b/LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs new file mode 100644 index 0000000..b49aa74 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs @@ -0,0 +1,45 @@ +namespace LeetCodeNet.G0101_0200.S0142_linked_list_cycle_ii { + +// #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List +// #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List +// #Big_O_Time_O(N)_Space_O(1) #2024_01_09_Time_72_ms_(94.58%)_Space_43.8_MB_(18.67%) + +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int x) { + * val = x; + * next = null; + * } + * } + */ +public class Solution { + public ListNode DetectCycle(ListNode head) { + if (head == null || head.next == null) { + return null; + } + ListNode slow = head; + ListNode fast = head; + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + if (slow == fast) { + break; + } + } + if (fast == null || fast.next == null) { + return null; + } + slow = head; + while (slow != fast) { + slow = slow.next; + fast = fast.next; + } + return slow; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/readme.md b/LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/readme.md new file mode 100644 index 0000000..8aeb2e4 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/readme.md @@ -0,0 +1,47 @@ +142\. Linked List Cycle II + +Medium + +Given the `head` of a linked list, return _the node where the cycle begins. If there is no cycle, return_ `null`. + +There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the `next` pointer. Internally, `pos` is used to denote the index of the node that tail's `next` pointer is connected to (**0-indexed**). It is `-1` if there is no cycle. **Note that** `pos` **is not passed as a parameter**. + +**Do not modify** the linked list. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist.png) + +**Input:** head = [3,2,0,-4], pos = 1 + +**Output:** tail connects to node index 1 + +**Explanation:** There is a cycle in the linked list, where tail connects to the second node. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test2.png) + +**Input:** head = [1,2], pos = 0 + +**Output:** tail connects to node index 0 + +**Explanation:** There is a cycle in the linked list, where tail connects to the first node. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test3.png) + +**Input:** head = [1], pos = -1 + +**Output:** no cycle + +**Explanation:** There is no cycle in the linked list. + +**Constraints:** + +* The number of the nodes in the list is in the range [0, 104]. +* -105 <= Node.val <= 105 +* `pos` is `-1` or a **valid index** in the linked-list. + +**Follow up:** Can you solve it using `O(1)` (i.e. constant) memory? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0146_lru_cache/LRUCache.cs b/LeetCodeNet/G0101_0200/S0146_lru_cache/LRUCache.cs new file mode 100644 index 0000000..ea6bfdc --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0146_lru_cache/LRUCache.cs @@ -0,0 +1,93 @@ +namespace LeetCodeNet.G0101_0200.S0146_lru_cache { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List +// #Doubly_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(1)_Space_O(capacity) #2024_01_09_Time_780_ms_(34.57%)_Space_239.2_MB_(12.44%) + +public class LRUCache { + private readonly int capacity; + private readonly Dictionary> cacheMap; + private readonly LinkedList cacheList; + + public LRUCache(int capacity) { + this.capacity = capacity; + cacheMap = new Dictionary>(capacity); + cacheList = new LinkedList(); + } + + public int Get(int key) { + if (cacheMap.TryGetValue(key, out var node)) { + cacheList.Remove(node); + cacheList.AddFirst(node); + return node.Value.Value; + } + return -1; + } + + public void Put(int key, int value) { + if (cacheMap.TryGetValue(key, out var node)) { + node.Value.Value = value; + cacheList.Remove(node); + cacheList.AddFirst(node); + } else { + if (cacheMap.Count >= capacity) { + var lastNode = cacheList.Last; + cacheMap.Remove(lastNode.Value.Key); + cacheList.RemoveLast(); + } + var newNode = new LinkedListNode(new CacheItem(key, value)); + cacheMap.Add(key, newNode); + cacheList.AddFirst(newNode); + } + } + + private class CacheItem { + public int Key { get; } + public int Value { get; set; } + + public CacheItem(int key, int value) { + Key = key; + Value = value; + } + } +} + +public class KeyNode { + private int _key; + private int _val; + private KeyNode _next; + + public int key { + get { return _key; } + set { _key = value; } + } + + public int val { + get { return _val; } + set { _val = value; } + } + + public KeyNode next { + get { return _next; } + set { _next = value; } + } + + public KeyNode() { + _key = int.MinValue; + _val = int.MinValue; + _next = null; + } + + public KeyNode(int key, int val): this() { + _key = key; + _val = val; + } +} + +/** + * Your LRUCache object will be instantiated and called as such: + * LRUCache obj = new LRUCache(capacity); + * int param_1 = obj.Get(key); + * obj.Put(key,value); + */ +} diff --git a/LeetCodeNet/G0101_0200/S0146_lru_cache/readme.md b/LeetCodeNet/G0101_0200/S0146_lru_cache/readme.md new file mode 100644 index 0000000..8bc0954 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0146_lru_cache/readme.md @@ -0,0 +1,39 @@ +146\. LRU Cache + +Medium + +Design a data structure that follows the constraints of a **[Least Recently Used (LRU) cache](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU)**. + +Implement the `LRUCache` class: + +* `LRUCache(int capacity)` Initialize the LRU cache with **positive** size `capacity`. +* `int get(int key)` Return the value of the `key` if the key exists, otherwise return `-1`. +* `void put(int key, int value)` Update the value of the `key` if the `key` exists. Otherwise, add the `key-value` pair to the cache. If the number of keys exceeds the `capacity` from this operation, **evict** the least recently used key. + +The functions `get` and `put` must each run in `O(1)` average time complexity. + +**Example 1:** + +**Input** ["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"] [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]] + +**Output:** [null, null, null, 1, null, -1, null, -1, 3, 4] + +**Explanation:** + + LRUCache lRUCache = new LRUCache(2); + lRUCache.put(1, 1); // cache is {1=1} + lRUCache.put(2, 2); // cache is {1=1, 2=2} + lRUCache.get(1); // return 1 + lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3} + lRUCache.get(2); // returns -1 (not found) + lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3} + lRUCache.get(1); // return -1 (not found) + lRUCache.get(3); // return 3 + lRUCache.get(4); // return 4 + +**Constraints:** + +* `1 <= capacity <= 3000` +* 0 <= key <= 104 +* 0 <= value <= 105 +* At most 2 * 105 calls will be made to `get` and `put`. diff --git a/LeetCodeNet/G0101_0200/S0148_sort_list/Solution.cs b/LeetCodeNet/G0101_0200/S0148_sort_list/Solution.cs new file mode 100644 index 0000000..d605d80 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0148_sort_list/Solution.cs @@ -0,0 +1,41 @@ +namespace LeetCodeNet.G0101_0200.S0148_sort_list { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List +// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Top_Interview_150_Divide_and_Conquer +// #Big_O_Time_O(log(N))_Space_O(log(N)) #2024_01_09_Time_141_ms_(45.08%)_Space_67.7_MB_(18.18%) + +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ +public class Solution { + public ListNode SortList(ListNode head) { + List nums = new List(); + ListNode temp = head; + while (temp != null) { + nums.Add(temp.val); + temp = temp.next; + } + _ = new int[nums.Count()]; + int[] arr = nums.ToArray(); + Array.Sort(arr); + temp = head; + int i = 0; + while (temp != null) { + temp.val = arr[i]; + temp = temp.next; + i++; + } + return head; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0148_sort_list/readme.md b/LeetCodeNet/G0101_0200/S0148_sort_list/readme.md new file mode 100644 index 0000000..94f637d --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0148_sort_list/readme.md @@ -0,0 +1,34 @@ +148\. Sort List + +Medium + +Given the `head` of a linked list, return _the list after sorting it in **ascending order**_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/09/14/sort_list_1.jpg) + +**Input:** head = [4,2,1,3] + +**Output:** [1,2,3,4] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/09/14/sort_list_2.jpg) + +**Input:** head = [-1,5,3,4,0] + +**Output:** [-1,0,3,4,5] + +**Example 3:** + +**Input:** head = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the list is in the range [0, 5 * 104]. +* -105 <= Node.val <= 105 + +**Follow up:** Can you sort the linked list in `O(n logn)` time and `O(1)` memory (i.e. constant space)? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs b/LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs new file mode 100644 index 0000000..c7d4774 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs @@ -0,0 +1,29 @@ +namespace LeetCodeNet.G0101_0200.S0152_maximum_product_subarray { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming +// #Dynamic_Programming_I_Day_6 #Level_2_Day_13_Dynamic_Programming #Udemy_Dynamic_Programming +// #Big_O_Time_O(N)_Space_O(1) #2024_01_11_Time_71_ms_(90.35%)_Space_42.7_MB_(13.88%) + +public class Solution { + public int MaxProduct(int[] nums) { + int ans = int.MinValue; + int cprod = 1; + foreach (int j in nums) { + cprod = cprod * j; + ans = Math.Max(ans, cprod); + if (cprod == 0) { + cprod = 1; + } + } + cprod = 1; + for (int i = nums.Length - 1; i >= 0; i--) { + cprod = cprod * nums[i]; + ans = Math.Max(ans, cprod); + if (cprod == 0) { + cprod = 1; + } + } + return ans; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/readme.md b/LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/readme.md new file mode 100644 index 0000000..13f4e95 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/readme.md @@ -0,0 +1,31 @@ +152\. Maximum Product Subarray + +Medium + +Given an integer array `nums`, find a contiguous non-empty subarray within the array that has the largest product, and return _the product_. + +It is **guaranteed** that the answer will fit in a **32-bit** integer. + +A **subarray** is a contiguous subsequence of the array. + +**Example 1:** + +**Input:** nums = [2,3,-2,4] + +**Output:** 6 + +**Explanation:** [2,3] has the largest product 6. + +**Example 2:** + +**Input:** nums = [-2,0,-1] + +**Output:** 0 + +**Explanation:** The result cannot be 2, because [-2,-1] is not a subarray. + +**Constraints:** + +* 1 <= nums.length <= 2 * 104 +* `-10 <= nums[i] <= 10` +* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs b/LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs new file mode 100644 index 0000000..3254449 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs @@ -0,0 +1,33 @@ +namespace LeetCodeNet.G0101_0200.S0153_find_minimum_in_rotated_sorted_array { + +// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search +// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Top_Interview_150_Binary_Search +// #Big_O_Time_O(log_N)_Space_O(log_N) #2024_01_11_Time_64_ms_(88.59%)_Space_40.9_MB_(17.68%) + +public class Solution { + private int FindMinUtil(int[] nums, int l, int r) { + if (l == r) { + return nums[l]; + } + int mid = (l + r) / 2; + if (mid == l && nums[mid] < nums[r]) { + return nums[l]; + } + if (mid - 1 >= 0 && nums[mid - 1] > nums[mid]) { + return nums[mid]; + } + if (nums[mid] < nums[l]) { + return FindMinUtil(nums, l, mid - 1); + } else if (nums[mid] > nums[r]) { + return FindMinUtil(nums, mid + 1, r); + } + return FindMinUtil(nums, l, mid - 1); + } + + public int FindMin(int[] nums) { + int l = 0; + int r = nums.Length - 1; + return FindMinUtil(nums, l, r); + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/readme.md b/LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/readme.md new file mode 100644 index 0000000..db0231d --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/readme.md @@ -0,0 +1,46 @@ +153\. Find Minimum in Rotated Sorted Array + +Medium + +Suppose an array of length `n` sorted in ascending order is **rotated** between `1` and `n` times. For example, the array `nums = [0,1,2,4,5,6,7]` might become: + +* `[4,5,6,7,0,1,2]` if it was rotated `4` times. +* `[0,1,2,4,5,6,7]` if it was rotated `7` times. + +Notice that **rotating** an array `[a[0], a[1], a[2], ..., a[n-1]]` 1 time results in the array `[a[n-1], a[0], a[1], a[2], ..., a[n-2]]`. + +Given the sorted rotated array `nums` of **unique** elements, return _the minimum element of this array_. + +You must write an algorithm that runs in `O(log n) time.` + +**Example 1:** + +**Input:** nums = [3,4,5,1,2] + +**Output:** 1 + +**Explanation:** The original array was [1,2,3,4,5] rotated 3 times. + +**Example 2:** + +**Input:** nums = [4,5,6,7,0,1,2] + +**Output:** 0 + +**Explanation:** The original array was [0,1,2,4,5,6,7] and it was rotated 4 times. + +**Example 3:** + +**Input:** nums = [11,13,15,17] + +**Output:** 11 + +**Explanation:** The original array was [11,13,15,17] and it was rotated 4 times. + +**Constraints:** + +* `n == nums.length` +* `1 <= n <= 5000` +* `-5000 <= nums[i] <= 5000` +* All the integers of `nums` are **unique**. +* `nums` is sorted and rotated between `1` and `n` times. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs b/LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs new file mode 100644 index 0000000..fb1501a --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs @@ -0,0 +1,59 @@ +namespace LeetCodeNet.G0101_0200.S0155_min_stack { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design +// #Data_Structure_II_Day_14_Stack_Queue #Programming_Skills_II_Day_18 #Level_2_Day_16_Design +// #Udemy_Design #Top_Interview_150_Stack #Big_O_Time_O(1)_Space_O(N) +// #2024_01_11_Time_105_ms_(95.77%)_Space_55.6_MB_(13.78%) + +public class MinStack { + private class Node { + public int min; + public int data; + public Node nextNode; + public Node previousNode; + + public Node(int min, int data, Node previousNode, Node nextNode) { + this.min = min; + this.data = data; + this.previousNode = previousNode; + this.nextNode = nextNode; + } + } + + private Node currentNode; + + // initialize your data structure here. + public MinStack() { + // no initialization needed. + } + + public void Push(int val) { + if (currentNode == null) { + currentNode = new Node(val, val, null, null); + } else { + currentNode.nextNode = new Node(Math.Min(currentNode.min, val), val, currentNode, null); + currentNode = currentNode.nextNode; + } + } + + public void Pop() { + currentNode = currentNode.previousNode; + } + + public int Top() { + return currentNode.data; + } + + public int GetMin() { + return currentNode.min; + } +} +} +/** + * Your MinStack object will be instantiated and called as such: + * MinStack obj = new MinStack(); + * obj.Push(val); + * obj.Pop(); + * int param_3 = obj.Top(); + * int param_4 = obj.GetMin(); + */ diff --git a/LeetCodeNet/G0101_0200/S0155_min_stack/readme.md b/LeetCodeNet/G0101_0200/S0155_min_stack/readme.md new file mode 100644 index 0000000..f3a3af2 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0155_min_stack/readme.md @@ -0,0 +1,39 @@ +155\. Min Stack + +Easy + +Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. + +Implement the `MinStack` class: + +* `MinStack()` initializes the stack object. +* `void push(int val)` pushes the element `val` onto the stack. +* `void pop()` removes the element on the top of the stack. +* `int top()` gets the top element of the stack. +* `int getMin()` retrieves the minimum element in the stack. + +**Example 1:** + +**Input** + + ["MinStack","push","push","push","getMin","pop","top","getMin"] + [[],[-2],[0],[-3],[],[],[],[]] + +**Output:** [null,null,null,null,-3,null,0,-2] + +**Explanation:** + + MinStack minStack = new MinStack(); + minStack.push(-2); + minStack.push(0); + minStack.push(-3); + minStack.getMin(); // return -3 + minStack.pop(); + minStack.top(); // return 0 + minStack.getMin(); // return -2 + +**Constraints:** + +* -231 <= val <= 231 - 1 +* Methods `pop`, `top` and `getMin` operations will always be called on **non-empty** stacks. +* At most 3 * 104 calls will be made to `push`, `pop`, `top`, and `getMin`. \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/Solution.cs b/LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/Solution.cs new file mode 100644 index 0000000..026b572 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/Solution.cs @@ -0,0 +1,28 @@ +namespace LeetCodeNet.G0101_0200.S0160_intersection_of_two_linked_lists { + +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List +// #Data_Structure_II_Day_11_Linked_List #Udemy_Linked_List #Big_O_Time_O(M+N)_Space_O(1) +// #2024_01_11_Time_118_ms_(53.65%)_Space_54.6_MB_(23.25%) + +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int x) { val = x; } + * } + */ +public class Solution { + public ListNode GetIntersectionNode(ListNode headA, ListNode headB) { + ListNode node1 = headA; + ListNode node2 = headB; + while (node1 != node2) { + node1 = node1 == null ? headB : node1.next; + node2 = node2 == null ? headA : node2.next; + } + return node1; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/readme.md b/LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/readme.md new file mode 100644 index 0000000..de0e1d8 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/readme.md @@ -0,0 +1,68 @@ +160\. Intersection of Two Linked Lists + +Easy + +Given the heads of two singly linked-lists `headA` and `headB`, return _the node at which the two lists intersect_. If the two linked lists have no intersection at all, return `null`. + +For example, the following two linked lists begin to intersect at node `c1`: + +![](https://assets.leetcode.com/uploads/2021/03/05/160_statement.png) + +The test cases are generated such that there are no cycles anywhere in the entire linked structure. + +**Note** that the linked lists must **retain their original structure** after the function returns. + +**Custom Judge:** + +The inputs to the **judge** are given as follows (your program is **not** given these inputs): + +* `intersectVal` - The value of the node where the intersection occurs. This is `0` if there is no intersected node. +* `listA` - The first linked list. +* `listB` - The second linked list. +* `skipA` - The number of nodes to skip ahead in `listA` (starting from the head) to get to the intersected node. +* `skipB` - The number of nodes to skip ahead in `listB` (starting from the head) to get to the intersected node. + +The judge will then create the linked structure based on these inputs and pass the two heads, `headA` and `headB` to your program. If you correctly return the intersected node, then your solution will be **accepted**. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/05/160_example_1_1.png) + +**Input:** intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3 + +**Output:** Intersected at '8' + +**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/05/160_example_2.png) + +**Input:** intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1 + +**Output:** Intersected at '2' + +**Explanation:** The intersected node's value is 2 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [1,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/03/05/160_example_3.png) + +**Input:** intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2 + +**Output:** No intersection + +**Explanation:** From the head of A, it reads as [2,6,4]. From the head of B, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be 0, while skipA and skipB can be arbitrary values. Explanation: The two lists do not intersect, so return null. + +**Constraints:** + +* The number of nodes of `listA` is in the `m`. +* The number of nodes of `listB` is in the `n`. +* 0 <= m, n <= 3 * 104 +* 1 <= Node.val <= 105 +* `0 <= skipA <= m` +* `0 <= skipB <= n` +* `intersectVal` is `0` if `listA` and `listB` do not intersect. +* `intersectVal == listA[skipA] == listB[skipB]` if `listA` and `listB` intersect. + +**Follow up:** Could you write a solution that runs in `O(n)` time and use only `O(1)` memory? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs b/LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs new file mode 100644 index 0000000..4ef29e0 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs @@ -0,0 +1,38 @@ +namespace LeetCodeNet.G0101_0200.S0169_majority_element { + +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting #Counting +// #Divide_and_Conquer #Data_Structure_II_Day_1_Array #Udemy_Famous_Algorithm +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2024_01_11_Time_98_ms_(66.71%)_Space_46.4_MB_(15.32%) + +public class Solution { + public int MajorityElement(int[] arr) { + int count = 1; + int majority = arr[0]; + // For Potential Majority Element + for (int i = 1; i < arr.Length; i++) { + if (arr[i] == majority) { + count++; + } else { + if (count > 1) { + count--; + } else { + majority = arr[i]; + } + } + } + // For Confirmation + count = 0; + foreach (int j in arr) { + if (j == majority) { + count++; + } + } + if (count >= (arr.Length / 2) + 1) { + return majority; + } else { + return -1; + } + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0169_majority_element/readme.md b/LeetCodeNet/G0101_0200/S0169_majority_element/readme.md new file mode 100644 index 0000000..5ea5071 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0169_majority_element/readme.md @@ -0,0 +1,27 @@ +169\. Majority Element + +Easy + +Given an array `nums` of size `n`, return _the majority element_. + +The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. + +**Example 1:** + +**Input:** nums = [3,2,3] + +**Output:** 3 + +**Example 2:** + +**Input:** nums = [2,2,1,1,1,2,2] + +**Output:** 2 + +**Constraints:** + +* `n == nums.length` +* 1 <= n <= 5 * 104 +* -231 <= nums[i] <= 231 - 1 + +**Follow-up:** Could you solve the problem in linear time and in `O(1)` space? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs b/LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs new file mode 100644 index 0000000..94d05b9 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs @@ -0,0 +1,26 @@ +namespace LeetCodeNet.G0101_0200.S0189_rotate_array { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Two_Pointers +// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String +// #Big_O_Time_O(n)_Space_O(1) #2024_01_11_Time_143_ms_(94.32%)_Space_62.9_MB_(24.95%) + +public class Solution { + private void Reverse(int[] nums, int l, int r) { + while (l <= r) { + int temp = nums[l]; + nums[l] = nums[r]; + nums[r] = temp; + l++; + r--; + } + } + + public void Rotate(int[] nums, int k) { + int n = nums.Length; + int t = n - (k % n); + Reverse(nums, 0, t - 1); + Reverse(nums, t, n - 1); + Reverse(nums, 0, n - 1); + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0189_rotate_array/readme.md b/LeetCodeNet/G0101_0200/S0189_rotate_array/readme.md new file mode 100644 index 0000000..390f269 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0189_rotate_array/readme.md @@ -0,0 +1,39 @@ +189\. Rotate Array + +Medium + +Given an array, rotate the array to the right by `k` steps, where `k` is non-negative. + +**Example 1:** + +**Input:** nums = [1,2,3,4,5,6,7], k = 3 + +**Output:** [5,6,7,1,2,3,4] + +**Explanation:** + + rotate 1 steps to the right: [7,1,2,3,4,5,6] + rotate 2 steps to the right: [6,7,1,2,3,4,5] + rotate 3 steps to the right: [5,6,7,1,2,3,4] + +**Example 2:** + +**Input:** nums = [-1,-100,3,99], k = 2 + +**Output:** [3,99,-1,-100] + +**Explanation:** + + rotate 1 steps to the right: [99,-1,-100,3] + rotate 2 steps to the right: [3,99,-1,-100] + +**Constraints:** + +* 1 <= nums.length <= 105 +* -231 <= nums[i] <= 231 - 1 +* 0 <= k <= 105 + +**Follow up:** + +* Try to come up with as many solutions as you can. There are at least **three** different ways to solve this problem. +* Could you do it in-place with `O(1)` extra space? \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs b/LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs new file mode 100644 index 0000000..ea05e1b --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs @@ -0,0 +1,28 @@ +namespace LeetCodeNet.G0101_0200.S0198_house_robber { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming +// #LeetCode_75_DP/1D #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_3 +// #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP +// #Big_O_Time_O(n)_Space_O(n) #2024_01_11_Time_44_ms_(99.89%)_Space_39.8_MB_(13.60%) + +public class Solution { + public int Rob(int[] nums) { + if (nums.Length == 0) { + return 0; + } + if (nums.Length == 1) { + return nums[0]; + } + if (nums.Length == 2) { + return Math.Max(nums[0], nums[1]); + } + int[] profit = new int[nums.Length]; + profit[0] = nums[0]; + profit[1] = Math.Max(nums[1], nums[0]); + for (int i = 2; i < nums.Length; i++) { + profit[i] = Math.Max(profit[i - 1], nums[i] + profit[i - 2]); + } + return profit[nums.Length - 1]; + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0198_house_robber/readme.md b/LeetCodeNet/G0101_0200/S0198_house_robber/readme.md new file mode 100644 index 0000000..4a93a57 --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0198_house_robber/readme.md @@ -0,0 +1,34 @@ +198\. House Robber + +Medium + +You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and **it will automatically contact the police if two adjacent houses were broken into on the same night**. + +Given an integer array `nums` representing the amount of money of each house, return _the maximum amount of money you can rob tonight **without alerting the police**_. + +**Example 1:** + +**Input:** nums = [1,2,3,1] + +**Output:** 4 + +**Explanation:** + + Rob house 1 (money = 1) and then rob house 3 (money = 3). + Total amount you can rob = 1 + 3 = 4. + +**Example 2:** + +**Input:** nums = [2,7,9,3,1] + +**Output:** 12 + +**Explanation:** + + Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1). + Total amount you can rob = 2 + 9 + 1 = 12. + +**Constraints:** + +* `1 <= nums.length <= 100` +* `0 <= nums[i] <= 400` \ No newline at end of file diff --git a/LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs b/LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs new file mode 100644 index 0000000..c4103ec --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs @@ -0,0 +1,37 @@ +namespace LeetCodeNet.G0101_0200.S0200_number_of_islands { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Depth_First_Search +// #Breadth_First_Search #Matrix #Union_Find +// #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search +// #Graph_Theory_I_Day_1_Matrix_Related_Problems #Level_1_Day_9_Graph/BFS/DFS #Udemy_Graph +// #Top_Interview_150_Graph_General #Big_O_Time_O(M*N)_Space_O(M*N) +// #2024_01_11_Time_119_ms_(51.45%)_Space_51_MB_(45.02%) + +public class Solution { + public int NumIslands(char[][] grid) { + int islands = 0; + if (grid != null && grid.Length != 0 && grid[0].Length != 0) { + for (int i = 0; i < grid.Length; i++) { + for (int j = 0; j < grid[0].Length; j++) { + if (grid[i][j] == '1') { + Dfs(grid, i, j); + islands++; + } + } + } + } + return islands; + } + + private void Dfs(char[][] grid, int x, int y) { + if (x < 0 || grid.Length <= x || y < 0 || grid[0].Length <= y || grid[x][y] != '1') { + return; + } + grid[x][y] = 'x'; + Dfs(grid, x + 1, y); + Dfs(grid, x - 1, y); + Dfs(grid, x, y + 1); + Dfs(grid, x, y - 1); + } +} +} diff --git a/LeetCodeNet/G0101_0200/S0200_number_of_islands/readme.md b/LeetCodeNet/G0101_0200/S0200_number_of_islands/readme.md new file mode 100644 index 0000000..0c4292d --- /dev/null +++ b/LeetCodeNet/G0101_0200/S0200_number_of_islands/readme.md @@ -0,0 +1,40 @@ +200\. Number of Islands + +Medium + +Given an `m x n` 2D binary grid `grid` which represents a map of `'1'`s (land) and `'0'`s (water), return _the number of islands_. + +An **island** is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. + +**Example 1:** + +**Input:** + + grid = [ + ["1","1","1","1","0"], + ["1","1","0","1","0"], + ["1","1","0","0","0"], + ["0","0","0","0","0"] + ] + +**Output:** 1 + +**Example 2:** + +**Input:** + + grid = [ + ["1","1","0","0","0"], + ["1","1","0","0","0"], + ["0","0","1","0","0"], + ["0","0","0","1","1"] + ] + +**Output:** 3 + +**Constraints:** + +* `m == grid.length` +* `n == grid[i].length` +* `1 <= m, n <= 300` +* `grid[i][j]` is `'0'` or `'1'`. \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs b/LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs new file mode 100644 index 0000000..4d8f899 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs @@ -0,0 +1,34 @@ +namespace LeetCodeNet.G0201_0300.S0206_reverse_linked_list { + +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion +// #LeetCode_75_LinkedList #Data_Structure_I_Day_8_Linked_List +// #Algorithm_I_Day_10_Recursion_Backtracking #Level_1_Day_3_Linked_List #Udemy_Linked_List +// #Big_O_Time_O(N)_Space_O(1) #2024_01_10_Time_57_ms_(95.02%)_Space_40.9_MB_(19.99%) + +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ +public class Solution { + public ListNode ReverseList(ListNode head) { + ListNode prev = null; + ListNode curr = head; + while (curr != null) { + ListNode next = curr.next; + curr.next = prev; + prev = curr; + curr = next; + } + return prev; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0206_reverse_linked_list/readme.md b/LeetCodeNet/G0201_0300/S0206_reverse_linked_list/readme.md new file mode 100644 index 0000000..a764d55 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0206_reverse_linked_list/readme.md @@ -0,0 +1,34 @@ +206\. Reverse Linked List + +Easy + +Given the `head` of a singly linked list, reverse the list, and return _the reversed list_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg) + +**Input:** head = [1,2,3,4,5] + +**Output:** [5,4,3,2,1] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg) + +**Input:** head = [1,2] + +**Output:** [2,1] + +**Example 3:** + +**Input:** head = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the list is the range `[0, 5000]`. +* `-5000 <= Node.val <= 5000` + +**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both? \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0207_course_schedule/Solution.cs b/LeetCodeNet/G0201_0300/S0207_course_schedule/Solution.cs new file mode 100644 index 0000000..eaf173c --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0207_course_schedule/Solution.cs @@ -0,0 +1,45 @@ +namespace LeetCodeNet.G0201_0300.S0207_course_schedule { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search +// #Breadth_First_Search #Graph #Topological_Sort #Top_Interview_150_Graph_General +// #Big_O_Time_O(N)_Space_O(N) #2024_01_10_Time_95_ms_(91.94%)_Space_47.1_MB_(36.27%) + +using System.Collections.Generic; + +public class Solution { + private static readonly int WHITE = 0; + private static readonly int GRAY = 1; + private static readonly int BLACK = 2; + + public bool CanFinish(int numCourses, int[][] prerequisites) { + List[] adj = new List[numCourses]; + for (int i = 0; i < numCourses; i++) { + adj[i] = new List(); + } + foreach (int[] pre in prerequisites) { + adj[pre[1]].Add(pre[0]); + } + int[] colors = new int[numCourses]; + for (int i = 0; i < numCourses; i++) { + if (colors[i] == WHITE && adj[i].Count > 0 && HasCycle(adj, i, colors)) { + return false; + } + } + return true; + } + + private bool HasCycle(List[] adj, int node, int[] colors) { + colors[node] = GRAY; + foreach (int nei in adj[node]) { + if (colors[nei] == GRAY) { + return true; + } + if (colors[nei] == WHITE && HasCycle(adj, nei, colors)) { + return true; + } + } + colors[node] = BLACK; + return false; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0207_course_schedule/readme.md b/LeetCodeNet/G0201_0300/S0207_course_schedule/readme.md new file mode 100644 index 0000000..a7b1e9c --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0207_course_schedule/readme.md @@ -0,0 +1,33 @@ +207\. Course Schedule + +Medium + +There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where prerequisites[i] = [ai, bi] indicates that you **must** take course bi first if you want to take course ai. + +* For example, the pair `[0, 1]`, indicates that to take course `0` you have to first take course `1`. + +Return `true` if you can finish all courses. Otherwise, return `false`. + +**Example 1:** + +**Input:** numCourses = 2, prerequisites = [[1,0]] + +**Output:** true + +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible. + +**Example 2:** + +**Input:** numCourses = 2, prerequisites = [[1,0],[0,1]] + +**Output:** false + +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible. + +**Constraints:** + +* 1 <= numCourses <= 105 +* `0 <= prerequisites.length <= 5000` +* `prerequisites[i].length == 2` +* 0 <= ai, bi < numCourses +* All the pairs prerequisites[i] are **unique**. \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs b/LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs new file mode 100644 index 0000000..977ab4a --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs @@ -0,0 +1,75 @@ +namespace LeetCodeNet.G0201_0300.S0208_implement_trie_prefix_tree { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Design #Trie +// #LeetCode_75_Trie #Level_2_Day_16_Design #Udemy_Trie_and_Heap #Top_Interview_150_Trie +// #Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) +// #2024_01_10_Time_178_ms_(88.12%)_Space_133.5_MB_(9.47%) + +public class Trie { + private TrieNode root; + private bool startWith; + + private class TrieNode { + // Initialize your data structure here. + public TrieNode[] children; + public bool isWord; + + public TrieNode() { + children = new TrieNode[26]; + } + } + + public Trie() { + root = new TrieNode(); + } + + // Inserts a word into the trie. + public void Insert(string word) { + Insert(word, root, 0); + } + + private void Insert(string word, TrieNode root, int idx) { + if (idx == word.Length) { + root.isWord = true; + return; + } + int index = word[idx] - 'a'; + if (root.children[index] == null) { + root.children[index] = new TrieNode(); + } + Insert(word, root.children[index], idx + 1); + } + + // Returns if the word is in the trie. + public bool Search(string word) { + return Search(word, root, 0); + } + + private bool Search(string word, TrieNode root, int idx) { + if (idx == word.Length) { + startWith = true; + return root.isWord; + } + int index = word[idx] - 'a'; + if (root.children[index] == null) { + startWith = false; + return false; + } + return Search(word, root.children[index], idx + 1); + } + + // Returns if there is any word in the trie + // that starts with the given prefix. + public bool StartsWith(string prefix) { + Search(prefix); + return startWith; + } +} +/** + * Your Trie object will be instantiated and called as such: + * Trie obj = new Trie(); + * obj.Insert(word); + * bool param_2 = obj.Search(word); + * bool param_3 = obj.StartsWith(prefix); + */ +} diff --git a/LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/readme.md b/LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/readme.md new file mode 100644 index 0000000..8121de3 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/readme.md @@ -0,0 +1,36 @@ +208\. Implement Trie (Prefix Tree) + +Medium + +A [**trie**](https://en.wikipedia.org/wiki/Trie) (pronounced as "try") or **prefix tree** is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. + +Implement the Trie class: + +* `Trie()` Initializes the trie object. +* `void insert(String word)` Inserts the string `word` into the trie. +* `boolean search(String word)` Returns `true` if the string `word` is in the trie (i.e., was inserted before), and `false` otherwise. +* `boolean startsWith(String prefix)` Returns `true` if there is a previously inserted string `word` that has the prefix `prefix`, and `false` otherwise. + +**Example 1:** + +**Input** + + ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] + [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] + +**Output:** [null, null, true, false, true, null, true] + +**Explanation:** + + Trie trie = new Trie(); + trie.insert("apple"); trie.search("apple"); // return True + trie.search("app"); // return False + trie.startsWith("app"); // return True + trie.insert("app"); + trie.search("app"); // return True + +**Constraints:** + +* `1 <= word.length, prefix.length <= 2000` +* `word` and `prefix` consist only of lowercase English letters. +* At most 3 * 104 calls **in total** will be made to `insert`, `search`, and `startsWith`. \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/Solution.cs b/LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/Solution.cs new file mode 100644 index 0000000..ab0ac16 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/Solution.cs @@ -0,0 +1,17 @@ +namespace LeetCodeNet.G0201_0300.S0215_kth_largest_element_in_an_array { + +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Heap_Priority_Queue +// #Divide_and_Conquer #Quickselect #LeetCode_75_Heap/Priority_Queue +// #Data_Structure_II_Day_20_Heap_Priority_Queue #Top_Interview_150_Heap +// #Big_O_Time_O(n*log(n))_Space_O(log(n)) #2024_01_10_Time_252_ms_(46.14%)_Space_55_MB_(26.22%) + +using System; + +public class Solution { + public int FindKthLargest(int[] nums, int k) { + int n = nums.Length; + Array.Sort(nums); + return nums[n - k]; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/readme.md b/LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/readme.md new file mode 100644 index 0000000..c4c64cb --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/readme.md @@ -0,0 +1,24 @@ +215\. Kth Largest Element in an Array + +Medium + +Given an integer array `nums` and an integer `k`, return _the_ kth _largest element in the array_. + +Note that it is the kth largest element in the sorted order, not the kth distinct element. + +**Example 1:** + +**Input:** nums = [3,2,1,5,6,4], k = 2 + +**Output:** 5 + +**Example 2:** + +**Input:** nums = [3,2,3,1,2,4,5,5,6], k = 4 + +**Output:** 4 + +**Constraints:** + +* 1 <= k <= nums.length <= 104 +* -104 <= nums[i] <= 104 \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0221_maximal_square/Solution.cs b/LeetCodeNet/G0201_0300/S0221_maximal_square/Solution.cs new file mode 100644 index 0000000..df31442 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0221_maximal_square/Solution.cs @@ -0,0 +1,38 @@ +namespace LeetCodeNet.G0201_0300.S0221_maximal_square { + +// #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_16 +// #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(m*n)_Space_O(m*n) +// #2024_01_10_Time_199_ms_(36.75%)_Space_59.5_MB_(84.44%) + +public class Solution { + public int MaximalSquare(char[][] matrix) { + int m = matrix.Length; + if (m == 0) { + return 0; + } + int n = matrix[0].Length; + if (n == 0) { + return 0; + } + int[][] dp = new int[m + 1][]; + for (int i = 0; i <= m; i++) { + dp[i] = new int[n + 1]; + } + int max = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (matrix[i][j] == '1') { + // 1 + minimum from cell above, cell to the left, cell diagonal upper-left + int next = 1 + Math.Min(dp[i][j], Math.Min(dp[i + 1][j], dp[i][j + 1])); + // keep track of the maximum value seen + if (next > max) { + max = next; + } + dp[i + 1][j + 1] = next; + } + } + } + return max * max; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0221_maximal_square/readme.md b/LeetCodeNet/G0201_0300/S0221_maximal_square/readme.md new file mode 100644 index 0000000..d9d3909 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0221_maximal_square/readme.md @@ -0,0 +1,34 @@ +221\. Maximal Square + +Medium + +Given an `m x n` binary `matrix` filled with `0`'s and `1`'s, _find the largest square containing only_ `1`'s _and return its area_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/26/max1grid.jpg) + +**Input:** matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] + +**Output:** 4 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/26/max2grid.jpg) + +**Input:** matrix = [["0","1"],["1","0"]] + +**Output:** 1 + +**Example 3:** + +**Input:** matrix = [["0"]] + +**Output:** 0 + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= m, n <= 300` +* `matrix[i][j]` is `'0'` or `'1'`. \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs b/LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs new file mode 100644 index 0000000..8c00421 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs @@ -0,0 +1,34 @@ +namespace LeetCodeNet.G0201_0300.S0226_invert_binary_tree { + +// #Easy #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree +// #Data_Structure_I_Day_12_Tree #Level_2_Day_6_Tree #Udemy_Tree_Stack_Queue +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n) +// #2024_01_10_Time_58_ms_(94.38%)_Space_40.3_MB_(8.09%) + +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 TreeNode InvertTree(TreeNode root) { + if (root == null) { + return null; + } + TreeNode temp = root.left; + root.left = InvertTree(root.right); + root.right = InvertTree(temp); + return root; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0226_invert_binary_tree/readme.md b/LeetCodeNet/G0201_0300/S0226_invert_binary_tree/readme.md new file mode 100644 index 0000000..339bf4e --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0226_invert_binary_tree/readme.md @@ -0,0 +1,32 @@ +226\. Invert Binary Tree + +Easy + +Given the `root` of a binary tree, invert the tree, and return _its root_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg) + +**Input:** root = [4,2,7,1,3,6,9] + +**Output:** [4,7,2,9,6,3,1] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/14/invert2-tree.jpg) + +**Input:** root = [2,1,3] + +**Output:** [2,3,1] + +**Example 3:** + +**Input:** root = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 100]`. +* `-100 <= Node.val <= 100` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs b/LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs new file mode 100644 index 0000000..e658e75 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs @@ -0,0 +1,55 @@ +namespace LeetCodeNet.G0201_0300.S0230_kth_smallest_element_in_a_bst { + +// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree +// #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree +// #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(n)_Space_O(n) +// #2024_01_10_Time_69_ms_(98.79%)_Space_45.2_MB_(12.59%) + +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 k; + private int count = 0; + private int val; + + public int KthSmallest(TreeNode root, int k) { + this.k = k; + Calculate(root); + return val; + } + + private void Calculate(TreeNode node) { + if (node.left == null && node.right == null) { + count++; + if (count == k) { + this.val = (int) node.val; + } + return; + } + if (node.left != null) { + Calculate(node.left); + } + count++; + if (count == k) { + this.val = (int) node.val; + return; + } + if (node.right != null) { + Calculate(node.right); + } + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/readme.md b/LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/readme.md new file mode 100644 index 0000000..840d758 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/readme.md @@ -0,0 +1,29 @@ +230\. Kth Smallest Element in a BST + +Medium + +Given the `root` of a binary search tree, and an integer `k`, return _the_ kth _smallest value (**1-indexed**) of all the values of the nodes in the tree_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/28/kthtree1.jpg) + +**Input:** root = [3,1,4,null,2], k = 1 + +**Output:** 1 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/01/28/kthtree2.jpg) + +**Input:** root = [5,3,6,2,4,null,null,1], k = 3 + +**Output:** 3 + +**Constraints:** + +* The number of nodes in the tree is `n`. +* 1 <= k <= n <= 104 +* 0 <= Node.val <= 104 + +**Follow up:** If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize? \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/Solution.cs b/LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/Solution.cs new file mode 100644 index 0000000..8d4dd7f --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/Solution.cs @@ -0,0 +1,54 @@ +namespace LeetCodeNet.G0201_0300.S0234_palindrome_linked_list { + +// #Easy #Top_100_Liked_Questions #Two_Pointers #Stack #Linked_List #Recursion +// #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1) +// #2024_01_10_Time_306_ms_(31.81%)_Space_66.1_MB_(33.64%) + +using LeetCodeNet.Com_github_leetcode; + +/** + * Definition for singly-linked list. + * public class ListNode { + * public int val; + * public ListNode next; + * public ListNode(int val=0, ListNode next=null) { + * this.val = val; + * this.next = next; + * } + * } + */ +public class Solution { + public bool IsPalindrome(ListNode head) { + int len = 0; + ListNode right = head; + // Calculate the length + while (right != null) { + right = right.next; + len++; + } + // Reverse the right half of the list + len = len / 2; + right = head; + for (int i = 0; i < len; i++) { + right = right.next; + } + ListNode prev = null; + while (right != null) { + ListNode next = right.next; + right.next = prev; + prev = right; + right = next; + } + // Compare left half and right half + for (int i = 0; i < len; i++) { + if (prev != null && head.val == prev.val) { + head = head.next; + prev = prev.next; + } else { + return false; + } + } + return true; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/readme.md b/LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/readme.md new file mode 100644 index 0000000..096f401 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/readme.md @@ -0,0 +1,28 @@ +234\. Palindrome Linked List + +Easy + +Given the `head` of a singly linked list, return `true` if it is a palindrome. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg) + +**Input:** head = [1,2,2,1] + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg) + +**Input:** head = [1,2] + +**Output:** false + +**Constraints:** + +* The number of nodes in the list is in the range [1, 105]. +* `0 <= Node.val <= 9` + +**Follow up:** Could you do it in `O(n)` time and `O(1)` space? \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs b/LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs new file mode 100644 index 0000000..db8590a --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs @@ -0,0 +1,38 @@ +namespace LeetCodeNet.G0201_0300.S0236_lowest_common_ancestor_of_a_binary_tree { + +// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree +// #LeetCode_75_Binary_Tree/DFS #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n) +// #2024_01_10_Time_76_ms_(98.04%)_Space_45.9_MB_(13.60%) + +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 x) { val = x; } + * } + */ +public class Solution { + public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null) { + return null; + } + if (root.val == p.val || root.val == q.val) { + return root; + } + TreeNode left = LowestCommonAncestor(root.left, p, q); + TreeNode right = LowestCommonAncestor(root.right, p, q); + if (left != null && right != null) { + return root; + } + if (left != null) { + return left; + } + return right; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/readme.md b/LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/readme.md new file mode 100644 index 0000000..6d39dba --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/readme.md @@ -0,0 +1,41 @@ +236\. Lowest Common Ancestor of a Binary Tree + +Medium + +Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. + +According to the [definition of LCA on Wikipedia](https://en.wikipedia.org/wiki/Lowest_common_ancestor): “The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in `T` that has both `p` and `q` as descendants (where we allow **a node to be a descendant of itself**).” + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/12/14/binarytree.png) + +**Input:** root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 + +**Output:** 3 + +**Explanation:** The LCA of nodes 5 and 1 is 3. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2018/12/14/binarytree.png) + +**Input:** root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4 + +**Output:** 5 + +**Explanation:** The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition. + +**Example 3:** + +**Input:** root = [1,2], p = 1, q = 2 + +**Output:** 1 + +**Constraints:** + +* The number of nodes in the tree is in the range [2, 105]. +* -109 <= Node.val <= 109 +* All `Node.val` are **unique**. +* `p != q` +* `p` and `q` will exist in the tree. \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs b/LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs new file mode 100644 index 0000000..4ff2a49 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs @@ -0,0 +1,30 @@ +namespace LeetCodeNet.G0201_0300.S0238_product_of_array_except_self { + +// #Medium #Top_100_Liked_Questions #Array #Prefix_Sum #LeetCode_75_Array/String +// #Data_Structure_II_Day_5_Array #Udemy_Arrays #Top_Interview_150_Array/String +// #Big_O_Time_O(n^2)_Space_O(n) #2024_01_10_Time_141_ms_(94.24%)_Space_58.3_MB_(10.01%) + +public class Solution { + public int[] ProductExceptSelf(int[] nums) { + int product = 1; + int[] ans = new int[nums.Length]; + foreach (int num in nums) { + product = product * num; + } + for (int i = 0; i < nums.Length; i++) { + if (nums[i] != 0) { + ans[i] = product / nums[i]; + } else { + int p = 1; + for (int j = 0; j < nums.Length; j++) { + if (j != i) { + p = p * nums[j]; + } + } + ans[i] = p; + } + } + return ans; + } +} +} diff --git a/LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/readme.md b/LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/readme.md new file mode 100644 index 0000000..aad514d --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/readme.md @@ -0,0 +1,29 @@ +238\. Product of Array Except Self + +Medium + +Given an integer array `nums`, return _an array_ `answer` _such that_ `answer[i]` _is equal to the product of all the elements of_ `nums` _except_ `nums[i]`. + +The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. + +You must write an algorithm that runs in `O(n)` time and without using the division operation. + +**Example 1:** + +**Input:** nums = [1,2,3,4] + +**Output:** [24,12,8,6] + +**Example 2:** + +**Input:** nums = [-1,1,0,-3,3] + +**Output:** [0,0,9,0,0] + +**Constraints:** + +* 2 <= nums.length <= 105 +* `-30 <= nums[i] <= 30` +* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. + +**Follow up:** Can you solve the problem in `O(1) `extra space complexity? (The output array **does not** count as extra space for space complexity analysis.) \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/Solution.cs b/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/Solution.cs new file mode 100644 index 0000000..cd9f647 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/Solution.cs @@ -0,0 +1,36 @@ +namespace LeetCodeNet.G0201_0300.S0239_sliding_window_maximum { + +// #Hard #Top_100_Liked_Questions #Array #Heap_Priority_Queue #Sliding_Window #Queue +// #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k) +// #2024_01_07_Time_493_ms_(46.05%)_Space_133.5_MB_(14.15%) + +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; + } +} +} 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..e566874 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/readme.md @@ -0,0 +1,54 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/Solution.cs b/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/Solution.cs new file mode 100644 index 0000000..2236eca --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/Solution.cs @@ -0,0 +1,23 @@ +namespace LeetCodeNet.G0201_0300.S0240_search_a_2d_matrix_ii { + +// #Medium #Top_100_Liked_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) +// #2024_01_07_Time_142_ms_(60.76%)_Space_54_MB_(79.75%) + +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; + } +} +} 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..2e111b7 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/readme.md @@ -0,0 +1,34 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0283_move_zeroes/Solution.cs b/LeetCodeNet/G0201_0300/S0283_move_zeroes/Solution.cs new file mode 100644 index 0000000..fcd5f81 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0283_move_zeroes/Solution.cs @@ -0,0 +1,24 @@ +namespace LeetCodeNet.G0201_0300.S0283_move_zeroes { + +// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #LeetCode_75_Two_Pointers +// #Algorithm_I_Day_3_Two_Pointers #Programming_Skills_I_Day_6_Array #Udemy_Arrays +// #Big_O_Time_O(n)_Space_O(1) #2024_01_07_Time_133_ms_(96.30%)_Space_57_MB_(17.07%) + +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; + } +} +} 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..a826cd7 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0283_move_zeroes/readme.md @@ -0,0 +1,26 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/Solution.cs b/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/Solution.cs new file mode 100644 index 0000000..9690938 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/Solution.cs @@ -0,0 +1,19 @@ +namespace LeetCodeNet.G0201_0300.S0287_find_the_duplicate_number { + +// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Two_Pointers #Bit_Manipulation +// #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n) +// #2024_01_07_Time_257_ms_(30.11%)_Space_70.4_MB_(7.03%) + +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; + } +} +} 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..fddfbbb --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/readme.md @@ -0,0 +1,45 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/MedianFinder.cs b/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/MedianFinder.cs new file mode 100644 index 0000000..3a9485a --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/MedianFinder.cs @@ -0,0 +1,35 @@ +namespace LeetCodeNet.G0201_0300.S0295_find_median_from_data_stream { + +// #Hard #Top_100_Liked_Questions #Sorting #Two_Pointers #Design #Heap_Priority_Queue #Data_Stream +// #Top_Interview_150_Heap #Big_O_Time_O(n*log_n)_Space_O(n) +// #2024_01_11_Time_658_ms_(24.88%)_Space_144_MB_(5.64%) + +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(); + */ +} 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..3928225 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/readme.md @@ -0,0 +1,43 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs b/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs new file mode 100644 index 0000000..d3015ea --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs @@ -0,0 +1,45 @@ +namespace LeetCodeNet.G0201_0300.S0300_longest_increasing_subsequence { + +// #Medium #Top_100_Liked_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 #Top_Interview_150_1D_DP #Big_O_Time_O(n*log_n)_Space_O(n) +// #2024_01_07_Time_80_ms_(89.11%)_Space_41.9_MB_(36.71%) + +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; + } +} +} 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..4b09231 --- /dev/null +++ b/LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/readme.md @@ -0,0 +1,34 @@ +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? \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs b/LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs new file mode 100644 index 0000000..56c82ba --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs @@ -0,0 +1,27 @@ +namespace LeetCodeNet.G0301_0400.S0322_coin_change { + +// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Breadth_First_Search +// #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_20 +// #Level_2_Day_12_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(m*n)_Space_O(amount) +// #2024_01_07_Time_78_ms_(90.63%)_Space_44.2_MB_(33.38%) + +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; + } +} +} 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..aff863c --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0322_coin_change/readme.md @@ -0,0 +1,35 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0338_counting_bits/Solution.cs b/LeetCodeNet/G0301_0400/S0338_counting_bits/Solution.cs new file mode 100644 index 0000000..5091b1a --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0338_counting_bits/Solution.cs @@ -0,0 +1,25 @@ +namespace LeetCodeNet.G0301_0400.S0338_counting_bits { + +// #Easy #Dynamic_Programming #Bit_Manipulation #LeetCode_75_Bit_Manipulation +// #Udemy_Bit_Manipulation #Big_O_Time_O(num)_Space_O(num) +// #2024_01_07_Time_67_ms_(98.82%)_Space_42.1_MB_(22.68%) + +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; + } +} +} 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..e0d6f7e --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0338_counting_bits/readme.md @@ -0,0 +1,41 @@ +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++)? \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/Solution.cs b/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/Solution.cs new file mode 100644 index 0000000..1f37d9b --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/Solution.cs @@ -0,0 +1,37 @@ +namespace LeetCodeNet.G0301_0400.S0347_top_k_frequent_elements { + +// #Medium #Top_100_Liked_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) #2024_01_07_Time_125_ms_(95.29%)_Space_50.6_MB_(12.11%) + +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; + } +} +} 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..9e5239f --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/readme.md @@ -0,0 +1,25 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0394_decode_string/Solution.cs b/LeetCodeNet/G0301_0400/S0394_decode_string/Solution.cs new file mode 100644 index 0000000..076e437 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0394_decode_string/Solution.cs @@ -0,0 +1,36 @@ +namespace LeetCodeNet.G0301_0400.S0394_decode_string { + +// #Medium #Top_100_Liked_Questions #String #Stack #Recursion #LeetCode_75_Stack +// #Level_1_Day_14_Stack #Udemy_Strings #Big_O_Time_O(n)_Space_O(n) +// #2024_01_07_Time_44_ms_(99.55%)_Space_38.2_MB_(26.91%) + +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(); + } +} +} 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..7c0a9e7 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0394_decode_string/readme.md @@ -0,0 +1,42 @@ +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]`. \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/Solution.cs b/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/Solution.cs new file mode 100644 index 0000000..5aa6605 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/Solution.cs @@ -0,0 +1,26 @@ +namespace 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) #2024_01_05_Time_95_ms_(97.38%)_Space_42.9_MB_(84.72%) + +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]; + } +} +} 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..56f915c --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0416_partition_equal_subset_sum/readme.md @@ -0,0 +1,26 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0437_path_sum_iii/Solution.cs b/LeetCodeNet/G0401_0500/S0437_path_sum_iii/Solution.cs new file mode 100644 index 0000000..66d5235 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0437_path_sum_iii/Solution.cs @@ -0,0 +1,47 @@ +namespace LeetCodeNet.G0401_0500.S0437_path_sum_iii { + +// #Medium #Depth_First_Search #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS #Level_2_Day_7_Tree +// #Big_O_Time_O(n)_Space_O(n) #2024_01_05_Time_76_ms_(97.16%)_Space_42.8_MB_(29.79%) + +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); + } + } +} +} 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..aad654c --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0437_path_sum_iii/readme.md @@ -0,0 +1,29 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/Solution.cs b/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/Solution.cs new file mode 100644 index 0000000..a06feda --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/Solution.cs @@ -0,0 +1,44 @@ +namespace 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) +// #2024_01_07_Time_103_ms_(97.89%)_Space_50.2_MB_(32.49%) + +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; + } +} +} 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..f3bc0a8 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/readme.md @@ -0,0 +1,35 @@ +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. diff --git a/LeetCodeNet/G0401_0500/S0494_target_sum/Solution.cs b/LeetCodeNet/G0401_0500/S0494_target_sum/Solution.cs new file mode 100644 index 0000000..b4ba2c5 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0494_target_sum/Solution.cs @@ -0,0 +1,44 @@ +namespace LeetCodeNet.G0401_0500.S0494_target_sum { + +// #Medium #Array #Dynamic_Programming #Backtracking #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s)) +// #2024_01_07_Time_62_ms_(99.32%)_Space_43.8_MB_(47.12%) + +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]; + } +} +} 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..745d09c --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0494_target_sum/readme.md @@ -0,0 +1,39 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/Solution.cs b/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/Solution.cs new file mode 100644 index 0000000..120007f --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/Solution.cs @@ -0,0 +1,41 @@ +namespace 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) +// #2024_01_07_Time_74_ms_(84.67%)_Space_42.6_MB_(8.90%) + +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 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); + } +} +} 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..a05ee9d --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/readme.md @@ -0,0 +1,30 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/Solution.cs b/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/Solution.cs new file mode 100644 index 0000000..9df2445 --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/Solution.cs @@ -0,0 +1,28 @@ +namespace 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) #2024_01_07_Time_135_ms_(46.56%)_Space_50.6_MB_(20.87%) + +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; + } +} +} 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..4b43707 --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/readme.md @@ -0,0 +1,23 @@ +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 \ No newline at end of file diff --git a/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/Solution.cs b/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/Solution.cs new file mode 100644 index 0000000..8bf94fc --- /dev/null +++ b/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/Solution.cs @@ -0,0 +1,29 @@ +namespace LeetCodeNet.G0601_0700.S0647_palindromic_substrings { + +// #Medium #String #Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n) +// #2024_01_07_Time_48_ms_(92.55%)_Space_37.2_MB_(34.47%) + +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]; + } +} +} 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..416355f --- /dev/null +++ b/LeetCodeNet/G0601_0700/S0647_palindromic_substrings/readme.md @@ -0,0 +1,30 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G0701_0800/S0739_daily_temperatures/Solution.cs b/LeetCodeNet/G0701_0800/S0739_daily_temperatures/Solution.cs new file mode 100644 index 0000000..ca9b4d9 --- /dev/null +++ b/LeetCodeNet/G0701_0800/S0739_daily_temperatures/Solution.cs @@ -0,0 +1,28 @@ +namespace LeetCodeNet.G0701_0800.S0739_daily_temperatures { + +// #Medium #Top_100_Liked_Questions #Array #Stack #Monotonic_Stack #LeetCode_75_Monotonic_Stack +// #Programming_Skills_II_Day_6 #Big_O_Time_O(n)_Space_O(n) +// #2024_01_07_Time_376_ms_(44.29%)_Space_71.9_MB_(21.96%) + +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; + } +} +} 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..54ef9fd --- /dev/null +++ b/LeetCodeNet/G0701_0800/S0739_daily_temperatures/readme.md @@ -0,0 +1,28 @@ +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` \ No newline at end of file diff --git a/LeetCodeNet/G0701_0800/S0763_partition_labels/Solution.cs b/LeetCodeNet/G0701_0800/S0763_partition_labels/Solution.cs new file mode 100644 index 0000000..7971d23 --- /dev/null +++ b/LeetCodeNet/G0701_0800/S0763_partition_labels/Solution.cs @@ -0,0 +1,32 @@ +namespace LeetCodeNet.G0701_0800.S0763_partition_labels { + +// #Medium #String #Hash_Table #Greedy #Two_Pointers #Data_Structure_II_Day_7_String +// #Big_O_Time_O(n)_Space_O(1) #2024_01_07_Time_82_ms_(98.72%)_Space_45.6_MB_(10.26%) + +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; + } +} +} 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..143aa81 --- /dev/null +++ b/LeetCodeNet/G0701_0800/S0763_partition_labels/readme.md @@ -0,0 +1,30 @@ +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. \ No newline at end of file diff --git a/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/Solution.cs b/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/Solution.cs new file mode 100644 index 0000000..0f9fffc --- /dev/null +++ b/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/Solution.cs @@ -0,0 +1,25 @@ +namespace LeetCodeNet.G1101_1200.S1143_longest_common_subsequence { + +// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #LeetCode_75_DP/Multidimensional +// #Algorithm_II_Day_17_Dynamic_Programming #Dynamic_Programming_I_Day_19 +// #Udemy_Dynamic_Programming #Big_O_Time_O(n*m)_Space_O(n*m) +// #2024_01_07_Time_59_ms_(90.45%)_Space_41.3_MB_(54.32%) + +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]; + } +} +} 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..b6504b9 --- /dev/null +++ b/LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/readme.md @@ -0,0 +1,40 @@ +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. \ No newline at end of file diff --git a/README.md b/README.md index f96b1f1..f38a603 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ C#-based LeetCode algorithm problem solutions, regularly updated. > ["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) * [Programming Skills II](#programming-skills-ii) @@ -21,177 +19,13 @@ C#-based LeetCode algorithm problem solutions, regularly updated. * [Level 1](#level-1) * [Level 2](#level-2) * [Udemy](#udemy) +* [Top Interview 150](#top-interview-150) * [Data Structure I](#data-structure-i) * [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/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| 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 II - -#### Day 1 - -| | | | | | -|-|-|-|-|-|- - -#### Day 2 - -| | | | | | -|-|-|-|-|-|- - -#### Day 3 - -| | | | | | -|-|-|-|-|-|- - -#### Day 4 - -| | | | | | -|-|-|-|-|-|- - -#### Day 5 - -| | | | | | -|-|-|-|-|-|- - -#### Day 6 - -| | | | | | -|-|-|-|-|-|- - -#### Day 7 - -| | | | | | -|-|-|-|-|-|- - -#### Day 8 - -| | | | | | -|-|-|-|-|-|- - -#### Day 9 - -| | | | | | -|-|-|-|-|-|- - -#### Day 10 - -| | | | | | -|-|-|-|-|-|- - -#### Day 11 - -| | | | | | -|-|-|-|-|-|- - -#### Day 12 - -| | | | | | -|-|-|-|-|-|- - -#### Day 13 - -| | | | | | -|-|-|-|-|-|- - -#### Day 14 - -| | | | | | -|-|-|-|-|-|- - -#### Day 15 - -| | | | | | -|-|-|-|-|-|- - -#### Day 16 - -| | | | | | -|-|-|-|-|-|- - -#### Day 17 - -| | | | | | -|-|-|-|-|-|- - -#### Day 18 - -| | | | | | -|-|-|-|-|-|- - -#### Day 19 - -| | | | | | -|-|-|-|-|-|- - -#### Day 20 - -| | | | | | -|-|-|-|-|-|- +* [Binary Search I](#binary-search-i) +* [Binary Search II](#binary-search-ii) ### Dynamic Programming I @@ -204,32 +38,38 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0198 |[House Robber](LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 44 | 99.89 #### Day 4 | | | | | | |-|-|-|-|-|- -| 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 85 | 88.80 #### Day 5 | | | | | | |-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 270 | 38.35 #### Day 6 | | | | | | |-|-|-|-|-|- +| 0152 |[Maximum Product Subarray](LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 71 | 90.35 #### Day 7 | | | | | | |-|-|-|-|-|- +| 0121 |[Best Time to Buy and Sell Stock](LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 328 | 35.43 #### Day 8 @@ -240,6 +80,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0139 |[Word Break](LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 64 | 98.44 | 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 #### Day 10 @@ -251,6 +92,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0096 |[Unique Binary Search Trees](LeetCodeNet/G0001_0100/S0096_unique_binary_search_trees/Solution.cs)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 13 | 98.48 #### Day 12 @@ -271,32 +113,39 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 74 | 94.37 +| 0221 |[Maximal Square](LeetCodeNet/G0201_0300/S0221_maximal_square/Solution.cs)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 199 | 36.75 #### Day 17 | | | | | | |-|-|-|-|-|- -| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 95.82 #### Day 18 | | | | | | |-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 59 | 90.45 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 #### Day 20 | | | | | | |-|-|-|-|-|- +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 #### Day 21 @@ -334,6 +183,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 #### Day 7 Array @@ -354,6 +204,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0104 |[Maximum Depth of Binary Tree](LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 65 | 93.31 #### Day 11 Containers and Libraries @@ -396,11 +247,13 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0739 |[Daily Temperatures](LeetCodeNet/G0701_0800/S0739_daily_temperatures/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 376 | 44.29 #### Day 7 | | | | | | |-|-|-|-|-|- +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image/Solution.cs)| 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 @@ -421,11 +274,13 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 103 | 97.89 #### Day 13 @@ -436,12 +291,13 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0138 |[Copy List with Random Pointer](LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 59 | 96.51 #### Day 15 | | | | | | |-|-|-|-|-|- -| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 84 | 77.30 +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 91.39 #### Day 16 @@ -457,6 +313,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0155 |[Min Stack](LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 105 | 95.77 #### Day 19 @@ -474,6 +331,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 119 | 51.45 #### Day 2 Matrix Related Problems @@ -608,22 +466,26 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00 +| 0206 |[Reverse Linked List](LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 57 | 95.02 #### Day 4 Linked List | | | | | | |-|-|-|-|-|- +| 0142 |[Linked List Cycle II](LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 72 | 94.58 #### Day 5 Greedy | | | | | | |-|-|-|-|-|- +| 0121 |[Best Time to Buy and Sell Stock](LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 328 | 35.43 #### Day 6 Tree | | | | | | |-|-|-|-|-|- +| 0102 |[Binary Tree Level Order Traversal](LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 97 | 98.14 #### Day 7 Binary Search @@ -634,37 +496,43 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 119 | 51.45 #### Day 10 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, 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/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- -| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 98.51 #### Day 14 Stack | | | | | | |-|-|-|-|-|- +| 0394 |[Decode String](LeetCodeNet/G0301_0400/S0394_decode_string/Solution.cs)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Big_O_Time_O(n)_Space_O(n) | 44 | 99.55 #### Day 15 Heap @@ -687,12 +555,14 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 69 | 90.79 +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 +| 0234 |[Palindrome Linked List](LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 306 | 31.81 #### Day 4 Linked List | | | | | | |-|-|-|-|-|- +| 0148 |[Sort List](LeetCodeNet/G0101_0200/S0148_sort_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 141 | 45.08 #### Day 5 Greedy @@ -703,22 +573,27 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0226 |[Invert Binary Tree](LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 58 | 94.38 #### Day 7 Tree | | | | | | |-|-|-|-|-|- +| 0543 |[Diameter of Binary Tree](LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/Solution.cs)| 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/Solution.cs)| Medium | Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 76 | 97.16 #### Day 8 Binary Search | | | | | | |-|-|-|-|-|- -| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 9 Binary Search Tree | | | | | | |-|-|-|-|-|- +| 0230 |[Kth Smallest Element in a BST](LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 69 | 98.79 #### Day 10 Graph/BFS/DFS @@ -734,32 +609,41 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0198 |[House Robber](LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 44 | 99.89 +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 95 | 97.38 +| 0152 |[Maximum Product Subarray](LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 71 | 90.35 #### Day 14 Sliding Window/Two Pointer | | | | | | |-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.84 +| 0076 |[Minimum Window Substring](LeetCodeNet/G0001_0100/S0076_minimum_window_substring/Solution.cs)| 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/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0155 |[Min Stack](LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 105 | 95.77 +| 0208 |[Implement Trie (Prefix Tree)](LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 178 | 88.12 #### Day 17 Interval | | | | | | |-|-|-|-|-|- +| 0056 |[Merge Intervals](LeetCodeNet/G0001_0100/S0056_merge_intervals/Solution.cs)| 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 @@ -775,8 +659,8 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 -| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 96 | 96.56 ### Udemy @@ -784,41 +668,54 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0007 |[Reverse Integer](LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs)| Medium | Top_Interview_Questions, Math | 23 | 59.02 -| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs)| Easy | Math | 42 | 34.61 +| 0136 |[Single Number](LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 87 | 93.37 +| 0007 |[Reverse Integer](LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs)| Medium | Top_Interview_Questions, Math | 14 | 99.26 +| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs)| Easy | Math | 1 | 99.90 #### Udemy Strings | | | | | | |-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.84 +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 82.01 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 95.82 +| 0394 |[Decode String](LeetCodeNet/G0301_0400/S0394_decode_string/Solution.cs)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Big_O_Time_O(n)_Space_O(n) | 44 | 99.55 +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- -| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0153 |[Find Minimum in Rotated Sorted Array](LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 64 | 88.59 #### Udemy Arrays | | | | | | |-|-|-|-|-|- -| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 -| 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 192 | 13.98 +| 0121 |[Best Time to Buy and Sell Stock](LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 328 | 35.43 +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 98.51 +| 0189 |[Rotate Array](LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 143 | 94.32 +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 98 | 93.59 +| 0238 |[Product of Array Except Self](LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 141 | 94.24 +| 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 178 | 36.64 +| 0239 |[Sliding Window Maximum](LeetCodeNet/G0201_0300/S0239_sliding_window_maximum/Solution.cs)| Hard | Top_100_Liked_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 | | | | | | |-|-|-|-|-|- | 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 -| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 34 | 76.14 #### Udemy Famous Algorithm | | | | | | |-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 270 | 38.35 +| 0169 |[Majority Element](LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 98 | 66.71 #### Udemy Sorting Algorithms @@ -829,54 +726,271 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- -| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 58 | 98.51 -| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 -| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 75 | 86.97 +| 0114 |[Flatten Binary Tree to Linked List](LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 52 | 98.71 +| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0142 |[Linked List Cycle II](LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 72 | 94.58 +| 0141 |[Linked List Cycle](LeetCodeNet/G0101_0200/S0141_linked_list_cycle/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 76 | 99.02 +| 0206 |[Reverse Linked List](LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 57 | 95.02 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00 +| 0160 |[Intersection of Two Linked Lists](LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 118 | 53.65 +| 0234 |[Palindrome Linked List](LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 306 | 31.81 +| 0138 |[Copy List with Random Pointer](LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 59 | 96.51 +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 +| 0146 |[LRU Cache](LeetCodeNet/G0101_0200/S0146_lru_cache/LRUCache.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 780 | 34.57 #### Udemy Tree Stack Queue | | | | | | |-|-|-|-|-|- +| 0094 |[Binary Tree Inorder Traversal](LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/Solution.cs)| 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 +| 0102 |[Binary Tree Level Order Traversal](LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 97 | 98.14 +| 0543 |[Diameter of Binary Tree](LeetCodeNet/G0501_0600/S0543_diameter_of_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 74 | 84.67 +| 0226 |[Invert Binary Tree](LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 58 | 94.38 +| 0104 |[Maximum Depth of Binary Tree](LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 65 | 93.31 +| 0124 |[Binary Tree Maximum Path Sum](LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 85 | 91.69 +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs)| 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 +| 0236 |[Lowest Common Ancestor of a Binary Tree](LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 76 | 98.04 #### Udemy Trie and Heap | | | | | | |-|-|-|-|-|- +| 0208 |[Implement Trie (Prefix Tree)](LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 178 | 88.12 #### Udemy Graph | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 119 | 51.45 #### Udemy Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs)| 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 +| 0139 |[Word Break](LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 64 | 98.44 +| 0152 |[Maximum Product Subarray](LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 71 | 90.35 +| 0198 |[House Robber](LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 44 | 99.89 +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 59 | 90.45 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 +| 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 99.81 #### Udemy Backtracking/Recursion | | | | | | |-|-|-|-|-|- -| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 -| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00 +| 0078 |[Subsets](LeetCodeNet/G0001_0100/S0078_subsets/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 96 | 96.56 #### Udemy Bit Manipulation | | | | | | |-|-|-|-|-|- +| 0338 |[Counting Bits](LeetCodeNet/G0301_0400/S0338_counting_bits/Solution.cs)| Easy | Dynamic_Programming, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 67 | 98.82 #### Udemy Design | | | | | | |-|-|-|-|-|- +| 0155 |[Min Stack](LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 105 | 95.77 + +### Top Interview 150 + +#### Top Interview 150 Array/String + +| | | | | | +|-|-|-|-|-|- +| 0169 |[Majority Element](LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 98 | 66.71 +| 0189 |[Rotate Array](LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 143 | 94.32 +| 0121 |[Best Time to Buy and Sell Stock](LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 328 | 35.43 +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 85 | 88.80 +| 0238 |[Product of Array Except Self](LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 141 | 94.24 +| 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 +| 0006 |[Zigzag Conversion](LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs)| Medium | String | 3 | 95.39 + +#### Top Interview 150 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 99.97 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 34 | 76.14 + +#### Top Interview 150 Sliding Window + +| | | | | | +|-|-|-|-|-|- +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.84 +| 0076 |[Minimum Window Substring](LeetCodeNet/G0001_0100/S0076_minimum_window_substring/Solution.cs)| 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 + +#### Top Interview 150 Matrix + +| | | | | | +|-|-|-|-|-|- +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 124 | 96.92 + +#### Top Interview 150 Hashmap + +| | | | | | +|-|-|-|-|-|- +| 0049 |[Group Anagrams](LeetCodeNet/G0001_0100/S0049_group_anagrams/Solution.cs)| 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 +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 98.51 +| 0128 |[Longest Consecutive Sequence](LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Big_O_Time_O(N_log_N)_Space_O(1) | 201 | 61.50 + +#### Top Interview 150 Intervals + +| | | | | | +|-|-|-|-|-|- +| 0056 |[Merge Intervals](LeetCodeNet/G0001_0100/S0056_merge_intervals/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 149 | 89.48 + +#### Top Interview 150 Stack + +| | | | | | +|-|-|-|-|-|- +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 82.01 +| 0155 |[Min Stack](LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 105 | 95.77 + +#### Top Interview 150 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0141 |[Linked List Cycle](LeetCodeNet/G0101_0200/S0141_linked_list_cycle/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 76 | 99.02 +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 91.39 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00 +| 0138 |[Copy List with Random Pointer](LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 59 | 96.51 +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 +| 0146 |[LRU Cache](LeetCodeNet/G0101_0200/S0146_lru_cache/LRUCache.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 780 | 34.57 + +#### Top Interview 150 Binary Tree General + +| | | | | | +|-|-|-|-|-|- +| 0104 |[Maximum Depth of Binary Tree](LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 65 | 93.31 +| 0226 |[Invert Binary Tree](LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 58 | 94.38 +| 0101 |[Symmetric Tree](LeetCodeNet/G0101_0200/S0101_symmetric_tree/Solution.cs)| 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 +| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 53 | 99.83 +| 0114 |[Flatten Binary Tree to Linked List](LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 52 | 98.71 +| 0124 |[Binary Tree Maximum Path Sum](LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 85 | 91.69 +| 0236 |[Lowest Common Ancestor of a Binary Tree](LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 76 | 98.04 + +#### Top Interview 150 Binary Tree BFS + +| | | | | | +|-|-|-|-|-|- +| 0102 |[Binary Tree Level Order Traversal](LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 97 | 98.14 + +#### Top Interview 150 Binary Search Tree + +| | | | | | +|-|-|-|-|-|- +| 0230 |[Kth Smallest Element in a BST](LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 69 | 98.79 +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs)| 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 + +#### Top Interview 150 Graph General + +| | | | | | +|-|-|-|-|-|- +| 0200 |[Number of Islands](LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 119 | 51.45 +| 0207 |[Course Schedule](LeetCodeNet/G0201_0300/S0207_course_schedule/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 95 | 91.94 + +#### Top Interview 150 Graph BFS + +| | | | | | +|-|-|-|-|-|- + +#### Top Interview 150 Trie + +| | | | | | +|-|-|-|-|-|- +| 0208 |[Implement Trie (Prefix Tree)](LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 178 | 88.12 + +#### Top Interview 150 Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 96 | 96.56 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00 +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00 +| 0079 |[Word Search](LeetCodeNet/G0001_0100/S0079_word_search/Solution.cs)| 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 + +#### Top Interview 150 Divide and Conquer + +| | | | | | +|-|-|-|-|-|- +| 0148 |[Sort List](LeetCodeNet/G0101_0200/S0148_sort_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 141 | 45.08 +| 0023 |[Merge k Sorted Lists](LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 3 | 97.54 + +#### Top Interview 150 Kadane's Algorithm + +| | | | | | +|-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 270 | 38.35 + +#### Top Interview 150 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0153 |[Find Minimum in Rotated Sorted Array](LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 64 | 88.59 +| 0004 |[Median of Two Sorted Arrays](LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1), AI_can_be_used_to_solve_the_task | 0 | 100.00 + +#### Top Interview 150 Heap + +| | | | | | +|-|-|-|-|-|- +| 0215 |[Kth Largest Element in an Array](LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 252 | 46.14 +| 0295 |[Find Median from Data Stream](LeetCodeNet/G0201_0300/S0295_find_median_from_data_stream/MedianFinder.cs)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Big_O_Time_O(n\*log_n)_Space_O(n) | 658 | 24.88 + +#### Top Interview 150 Bit Manipulation + +| | | | | | +|-|-|-|-|-|- +| 0136 |[Single Number](LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 87 | 93.37 + +#### Top Interview 150 Math + +| | | | | | +|-|-|-|-|-|- +| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs)| Easy | Math | 1 | 99.90 + +#### Top Interview 150 1D DP + +| | | | | | +|-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 +| 0198 |[House Robber](LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 44 | 99.89 +| 0139 |[Word Break](LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 64 | 98.44 +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 + +#### Top Interview 150 Multidimensional DP + +| | | | | | +|-|-|-|-|-|- +| 0064 |[Minimum Path Sum](LeetCodeNet/G0001_0100/S0064_minimum_path_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 74 | 94.37 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 95.82 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 +| 0221 |[Maximal Square](LeetCodeNet/G0201_0300/S0221_maximal_square/Solution.cs)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 199 | 36.75 ### Data Structure I @@ -884,17 +998,19 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 270 | 38.35 #### Day 2 Array | | | | | | |-|-|-|-|-|- -| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 98.51 #### Day 3 Array | | | | | | |-|-|-|-|-|- +| 0121 |[Best Time to Buy and Sell Stock](LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 328 | 35.43 #### Day 4 Array @@ -905,6 +1021,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 #### Day 6 String @@ -915,33 +1032,40 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 +| 0141 |[Linked List Cycle](LeetCodeNet/G0101_0200/S0141_linked_list_cycle/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 76 | 99.02 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00 #### Day 8 Linked List | | | | | | |-|-|-|-|-|- +| 0206 |[Reverse Linked List](LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 57 | 95.02 #### Day 9 Stack Queue | | | | | | |-|-|-|-|-|- -| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 96.68 +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 82.01 #### Day 10 Tree | | | | | | |-|-|-|-|-|- +| 0094 |[Binary Tree Inorder Traversal](LeetCodeNet/G0001_0100/S0094_binary_tree_inorder_traversal/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0102 |[Binary Tree Level Order Traversal](LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 97 | 98.14 +| 0104 |[Maximum Depth of Binary Tree](LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 65 | 93.31 +| 0101 |[Symmetric Tree](LeetCodeNet/G0101_0200/S0101_symmetric_tree/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0226 |[Invert Binary Tree](LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 58 | 94.38 #### Day 13 Tree @@ -952,6 +1076,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0098 |[Validate Binary Search Tree](LeetCodeNet/G0001_0100/S0098_validate_binary_search_tree/Solution.cs)| 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 @@ -959,27 +1084,35 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 +| 0136 |[Single Number](LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 87 | 93.37 +| 0169 |[Majority Element](LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 98 | 66.71 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 34 | 76.14 #### Day 2 Array | | | | | | |-|-|-|-|-|- +| 0075 |[Sort Colors](LeetCodeNet/G0001_0100/S0075_sort_colors/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 142 | 60.76 #### Day 5 Array | | | | | | |-|-|-|-|-|- +| 0238 |[Product of Array Except Self](LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 141 | 94.24 +| 0560 |[Subarray Sum Equals K](LeetCodeNet/G0501_0600/S0560_subarray_sum_equals_k/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 135 | 46.56 #### Day 6 String @@ -990,50 +1123,56 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0763 |[Partition Labels](LeetCodeNet/G0701_0800/S0763_partition_labels/Solution.cs)| Medium | 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/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- -| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 95.82 #### Day 10 Linked List | | | | | | |-|-|-|-|-|- -| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 84 | 77.30 +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 91.39 +| 0142 |[Linked List Cycle II](LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 72 | 94.58 #### Day 11 Linked List | | | | | | |-|-|-|-|-|- +| 0160 |[Intersection of Two Linked Lists](LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 118 | 53.65 #### Day 12 Linked List | | | | | | |-|-|-|-|-|- -| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 58 | 98.51 +| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Day 13 Linked List | | | | | | |-|-|-|-|-|- -| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 75 | 86.97 +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 #### Day 14 Stack Queue | | | | | | |-|-|-|-|-|- +| 0155 |[Min Stack](LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 105 | 95.77 #### Day 15 Tree | | | | | | |-|-|-|-|-|- +| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 53 | 99.83 #### Day 16 Tree @@ -1044,11 +1183,13 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0230 |[Kth Smallest Element in a BST](LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 69 | 98.79 #### Day 18 Tree | | | | | | |-|-|-|-|-|- +| 0236 |[Lowest Common Ancestor of a Binary Tree](LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 76 | 98.04 #### Day 19 Graph @@ -1059,6 +1200,8 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0215 |[Kth Largest Element in an Array](LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 252 | 46.14 +| 0347 |[Top K Frequent Elements](LeetCodeNet/G0301_0400/S0347_top_k_frequent_elements/Solution.cs)| Medium | Top_100_Liked_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 @@ -1071,17 +1214,19 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 2 Two Pointers | | | | | | |-|-|-|-|-|- +| 0189 |[Rotate Array](LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 143 | 94.32 #### Day 3 Two Pointers | | | | | | |-|-|-|-|-|- +| 0283 |[Move Zeroes](LeetCodeNet/G0201_0300/S0283_move_zeroes/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 133 | 96.30 #### Day 4 Two Pointers @@ -1092,13 +1237,13 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 69 | 90.79 +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 #### Day 6 Sliding Window | | | | | | |-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.84 #### Day 7 Breadth First Search Depth First Search @@ -1119,18 +1264,21 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00 +| 0206 |[Reverse Linked List](LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 57 | 95.02 #### Day 11 Recursion Backtracking | | | | | | |-|-|-|-|-|- -| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 96 | 96.56 #### Day 12 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 +| 0198 |[House Robber](LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 44 | 99.89 #### Day 13 Bit Manipulation @@ -1141,6 +1289,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0136 |[Single Number](LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 87 | 93.37 ### Algorithm II @@ -1148,35 +1297,39 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 +| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0153 |[Find Minimum in Rotated Sorted Array](LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 64 | 88.59 #### Day 3 Two Pointers | | | | | | |-|-|-|-|-|- -| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 34 | 76.14 #### Day 4 Two Pointers | | | | | | |-|-|-|-|-|- -| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 248 | 11.15 +| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 99.97 #### Day 5 Sliding Window | | | | | | |-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](LeetCodeNet/G0401_0500/S0438_find_all_anagrams_in_a_string/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 119 | 51.45 #### Day 7 Breadth First Search Depth First Search @@ -1192,56 +1345,65 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0078 |[Subsets](LeetCodeNet/G0001_0100/S0078_subsets/Solution.cs)| 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 | | | | | | |-|-|-|-|-|- -| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00 #### Day 11 Recursion Backtracking | | | | | | |-|-|-|-|-|- -| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 +| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00 +| 0079 |[Word Search](LeetCodeNet/G0001_0100/S0079_word_search/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 +| 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 85 | 88.80 +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 16 | 93.42 #### Day 14 Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 95.82 #### Day 15 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0139 |[Word Break](LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 64 | 98.44 #### Day 16 Dynamic Programming | | | | | | |-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, 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/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 +| 0322 |[Coin Change](LeetCodeNet/G0301_0400/S0322_coin_change/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 #### Day 19 Bit Manipulation @@ -1258,46 +1420,292 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +### Binary Search I + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 + +#### 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](LeetCodeNet/G0001_0100/S0074_search_a_2d_matrix/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- +| 0153 |[Find Minimum in Rotated Sorted Array](LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 64 | 88.59 + +### Binary Search II + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 80 | 89.11 + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- +| 0287 |[Find the Duplicate Number](LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 257 | 30.11 + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- +| 0240 |[Search a 2D Matrix II](LeetCodeNet/G0201_0300/S0240_search_a_2d_matrix_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 142 | 60.76 + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 + +| | | | | | +|-|-|-|-|-|- + +#### Day 15 + +| | | | | | +|-|-|-|-|-|- + +#### Day 16 + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 + +| | | | | | +|-|-|-|-|-|- + +#### Day 18 + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 + +| | | | | | +|-|-|-|-|-|- + ## Algorithms | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|--------- -| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| 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 -| 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 192 | 13.98 -| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Algorithm_II_Day_10_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 -| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_I_Day_1_Binary_Search, Binary_Search_I_Day_2, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 -| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_5, 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_11, Level_2_Day_8_Binary_Search, Udemy_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 -| 0032 |[Longest Valid Parentheses](LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/Solution.cs)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Stack, Big_O_Time_O(n)_Space_O(1) | 49 | 96.18 -| 0031 |[Next Permutation](LeetCodeNet/G0001_0100/S0031_next_permutation/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 202 | 5.19 -| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_13_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(k) | 75 | 86.97 -| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_12_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 58 | 98.51 -| 0023 |[Merge k Sorted Lists](LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 78 | 98.24 -| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 -| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Data_Structure_I_Day_7_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 -| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Data_Structure_I_Day_9_Stack_Queue, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 53 | 96.68 -| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Big_O_Time_O(L)_Space_O(L) | 69 | 90.79 -| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(4^n)_Space_O(n) | 108 | 95.24 -| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_1_Array, Algorithm_II_Day_3_Two_Pointers, Udemy_Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 -| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 248 | 11.15 -| 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 59 | 96.10 -| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs)| Easy | Math, Udemy_Integers | 42 | 34.61 -| 0008 |[String to Integer (atoi)](LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/Solution.cs)| Medium | Top_Interview_Questions, String | 43 | 99.83 -| 0007 |[Reverse Integer](LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 23 | 59.02 -| 0006 |[Zigzag Conversion](LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs)| Medium | String | 59 | 99.87 -| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Data_Structure_II_Day_9_String, Algorithm_II_Day_14_Dynamic_Programming, Dynamic_Programming_I_Day_17, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 -| 0004 |[Median of Two Sorted Arrays](LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1) | 83 | 96.35 -| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Algorithm_I_Day_6_Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Udemy_Strings, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 -| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 84 | 77.30 -| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 +| 1143 |[Longest Common Subsequence](LeetCodeNet/G1101_1200/S1143_longest_common_subsequence/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, 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/Solution.cs)| Medium | 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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_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/Solution.cs)| Medium | 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/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | 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/Solution.cs)| 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/Solution.cs)| Medium | Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, 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/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Easy | Dynamic_Programming, Bit_Manipulation, LeetCode_75_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/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(m\*n)_Space_O(amount) | 78 | 90.63 +| 0300 |[Longest Increasing Subsequence](LeetCodeNet/G0201_0300/S0300_longest_increasing_subsequence/Solution.cs)| Medium | Top_100_Liked_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, Top_Interview_150_1D_DP, 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/MedianFinder.cs)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Top_Interview_150_Heap, Big_O_Time_O(n\*log_n)_Space_O(n) | 658 | 24.88 +| 0287 |[Find the Duplicate Number](LeetCodeNet/G0201_0300/S0287_find_the_duplicate_number/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_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/Solution.cs)| Medium | Top_100_Liked_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/Solution.cs)| Hard | Top_100_Liked_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 +| 0238 |[Product of Array Except Self](LeetCodeNet/G0201_0300/S0238_product_of_array_except_self/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Data_Structure_II_Day_5_Array, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 141 | 94.24 +| 0236 |[Lowest Common Ancestor of a Binary Tree](LeetCodeNet/G0201_0300/S0236_lowest_common_ancestor_of_a_binary_tree/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Data_Structure_II_Day_18_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(n)_Space_O(n) | 76 | 98.04 +| 0234 |[Palindrome Linked List](LeetCodeNet/G0201_0300/S0234_palindrome_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Level_2_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 306 | 31.81 +| 0230 |[Kth Smallest Element in a BST](LeetCodeNet/G0201_0300/S0230_kth_smallest_element_in_a_bst/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_II_Day_17_Tree, Level_2_Day_9_Binary_Search_Tree, Top_Interview_150_Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 69 | 98.79 +| 0226 |[Invert Binary Tree](LeetCodeNet/G0201_0300/S0226_invert_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_12_Tree, Level_2_Day_6_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(n)_Space_O(n) | 58 | 94.38 +| 0221 |[Maximal Square](LeetCodeNet/G0201_0300/S0221_maximal_square/Solution.cs)| Medium | Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(m\*n)_Space_O(m\*n) | 199 | 36.75 +| 0215 |[Kth Largest Element in an Array](LeetCodeNet/G0201_0300/S0215_kth_largest_element_in_an_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Data_Structure_II_Day_20_Heap_Priority_Queue, Top_Interview_150_Heap, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 252 | 46.14 +| 0208 |[Implement Trie (Prefix Tree)](LeetCodeNet/G0201_0300/S0208_implement_trie_prefix_tree/Trie.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Level_2_Day_16_Design, Udemy_Trie_and_Heap, Top_Interview_150_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 178 | 88.12 +| 0207 |[Course Schedule](LeetCodeNet/G0201_0300/S0207_course_schedule/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Top_Interview_150_Graph_General, Big_O_Time_O(N)_Space_O(N) | 95 | 91.94 +| 0206 |[Reverse Linked List](LeetCodeNet/G0201_0300/S0206_reverse_linked_list/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Data_Structure_I_Day_8_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 57 | 95.02 +| 0200 |[Number of Islands](LeetCodeNet/G0101_0200/S0200_number_of_islands/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search, Graph_Theory_I_Day_1_Matrix_Related_Problems, Level_1_Day_9_Graph/BFS/DFS, Udemy_Graph, Top_Interview_150_Graph_General, Big_O_Time_O(M\*N)_Space_O(M\*N) | 119 | 51.45 +| 0198 |[House Robber](LeetCodeNet/G0101_0200/S0198_house_robber/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_3, Level_2_Day_12_Dynamic_Programming, Udemy_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(n)_Space_O(n) | 44 | 99.89 +| 0189 |[Rotate Array](LeetCodeNet/G0101_0200/S0189_rotate_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Algorithm_I_Day_2_Two_Pointers, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 143 | 94.32 +| 0169 |[Majority Element](LeetCodeNet/G0101_0200/S0169_majority_element/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Data_Structure_II_Day_1_Array, Udemy_Famous_Algorithm, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 98 | 66.71 +| 0160 |[Intersection of Two Linked Lists](LeetCodeNet/G0101_0200/S0160_intersection_of_two_linked_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Udemy_Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 118 | 53.65 +| 0155 |[Min Stack](LeetCodeNet/G0101_0200/S0155_min_stack/MinStack.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Data_Structure_II_Day_14_Stack_Queue, Programming_Skills_II_Day_18, Level_2_Day_16_Design, Udemy_Design, Top_Interview_150_Stack, Big_O_Time_O(1)_Space_O(N) | 105 | 95.77 +| 0153 |[Find Minimum in Rotated Sorted Array](LeetCodeNet/G0101_0200/S0153_find_minimum_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_II_Day_2_Binary_Search, Binary_Search_I_Day_12, Udemy_Binary_Search, Top_Interview_150_Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 64 | 88.59 +| 0152 |[Maximum Product Subarray](LeetCodeNet/G0101_0200/S0152_maximum_product_subarray/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Dynamic_Programming_I_Day_6, Level_2_Day_13_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 71 | 90.35 +| 0148 |[Sort List](LeetCodeNet/G0101_0200/S0148_sort_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Level_2_Day_4_Linked_List, Top_Interview_150_Divide_and_Conquer, Big_O_Time_O(log(N))_Space_O(log(N)) | 141 | 45.08 +| 0146 |[LRU Cache](LeetCodeNet/G0101_0200/S0146_lru_cache/LRUCache.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 780 | 34.57 +| 0142 |[Linked List Cycle II](LeetCodeNet/G0101_0200/S0142_linked_list_cycle_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_10_Linked_List, Level_1_Day_4_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 72 | 94.58 +| 0141 |[Linked List Cycle](LeetCodeNet/G0101_0200/S0141_linked_list_cycle/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_I_Day_7_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(N)_Space_O(1) | 76 | 99.02 +| 0139 |[Word Break](LeetCodeNet/G0101_0200/S0139_word_break/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Algorithm_II_Day_15_Dynamic_Programming, Dynamic_Programming_I_Day_9, Udemy_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 64 | 98.44 +| 0138 |[Copy List with Random Pointer](LeetCodeNet/G0101_0200/S0138_copy_list_with_random_pointer/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Programming_Skills_II_Day_14, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(N)_Space_O(N) | 59 | 96.51 +| 0136 |[Single Number](LeetCodeNet/G0101_0200/S0136_single_number/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Data_Structure_II_Day_1_Array, Algorithm_I_Day_14_Bit_Manipulation, Udemy_Integers, Top_Interview_150_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 87 | 93.37 +| 0131 |[Palindrome Partitioning](LeetCodeNet/G0101_0200/S0131_palindrome_partitioning/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(N\*2^N)_Space_O(2^N\*N) | 677 | 38.30 +| 0128 |[Longest Consecutive Sequence](LeetCodeNet/G0101_0200/S0128_longest_consecutive_sequence/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Top_Interview_150_Hashmap, Big_O_Time_O(N_log_N)_Space_O(1) | 201 | 61.50 +| 0124 |[Binary Tree Maximum Path Sum](LeetCodeNet/G0101_0200/S0124_binary_tree_maximum_path_sum/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(N) | 85 | 91.69 +| 0121 |[Best Time to Buy and Sell Stock](LeetCodeNet/G0101_0200/S0121_best_time_to_buy_and_sell_stock/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Data_Structure_I_Day_3_Array, Dynamic_Programming_I_Day_7, Level_1_Day_5_Greedy, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(N)_Space_O(1) | 328 | 35.43 +| 0114 |[Flatten Binary Tree to Linked List](LeetCodeNet/G0101_0200/S0114_flatten_binary_tree_to_linked_list/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Udemy_Linked_List, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(N) | 52 | 98.71 +| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](LeetCodeNet/G0101_0200/S0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(N) | 53 | 99.83 +| 0104 |[Maximum Depth of Binary Tree](LeetCodeNet/G0101_0200/S0104_maximum_depth_of_binary_tree/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Data_Structure_I_Day_11_Tree, Programming_Skills_I_Day_10_Linked_List_and_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(H) | 65 | 93.31 +| 0102 |[Binary Tree Level Order Traversal](LeetCodeNet/G0101_0200/S0102_binary_tree_level_order_traversal/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_11_Tree, Level_1_Day_6_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_BFS, Big_O_Time_O(N)_Space_O(N) | 97 | 98.14 +| 0101 |[Symmetric Tree](LeetCodeNet/G0101_0200/S0101_symmetric_tree/Solution.cs)| 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, Top_Interview_150_Binary_Tree_General, 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/Solution.cs)| 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, Top_Interview_150_Binary_Search_Tree, 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/Solution.cs)| Medium | 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/Solution.cs)| 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/Solution.cs)| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 152 | 99.69 +| 0078 |[Subsets](LeetCodeNet/G0001_0100/S0078_subsets/Solution.cs)| 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/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Top_Interview_150_Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 56 | 98.72 +| 0075 |[Sort Colors](LeetCodeNet/G0001_0100/S0075_sort_colors/Solution.cs)| 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/Solution.cs)| 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, Top_Interview_150_Binary_Search, Big_O_Time_O(endRow+endCol)_Space_O(1) | 76 | 90.98 +| 0073 |[Set Matrix Zeroes](LeetCodeNet/G0001_0100/S0073_set_matrix_zeroes/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 124 | 96.92 +| 0072 |[Edit Distance](LeetCodeNet/G0001_0100/S0072_edit_distance/Solution.cs)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(n^2)_Space_O(n2) | 51 | 95.38 +| 0070 |[Climbing Stairs](LeetCodeNet/G0001_0100/S0070_climbing_stairs/Solution.cs)| 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, Top_Interview_150_1D_DP, Big_O_Time_O(n)_Space_O(n) | 15 | 94.90 +| 0064 |[Minimum Path Sum](LeetCodeNet/G0001_0100/S0064_minimum_path_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(m\*n)_Space_O(m\*n) | 74 | 94.37 +| 0062 |[Unique Paths](LeetCodeNet/G0001_0100/S0062_unique_paths/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, 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/Solution.cs)| 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, Top_Interview_150_Intervals, Big_O_Time_O(n_log_n)_Space_O(n) | 149 | 89.48 +| 0055 |[Jump Game](LeetCodeNet/G0001_0100/S0055_jump_game/Solution.cs)| 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, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 189 | 38.02 +| 0053 |[Maximum Subarray](LeetCodeNet/G0001_0100/S0053_maximum_subarray/Solution.cs)| Medium | 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, Top_Interview_150_Kadane's_Algorithm, Big_O_Time_O(n)_Space_O(1) | 270 | 38.35 +| 0051 |[N-Queens](LeetCodeNet/G0001_0100/S0051_n_queens/Solution.cs)| 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/Solution.cs)| 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, Top_Interview_150_Hashmap, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 145 | 96.20 +| 0048 |[Rotate Image](LeetCodeNet/G0001_0100/S0048_rotate_image/Solution.cs)| 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, Top_Interview_150_Matrix, Big_O_Time_O(n^2)_Space_O(1) | 92 | 97.78 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations/Solution.cs)| 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, Top_Interview_150_Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 96 | 96.56 +| 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_4, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 85 | 88.80 +| 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Dynamic_Programming_I_Day_9, Udemy_Two_Pointers, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 +| 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 178 | 36.64 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Backtracking, Algorithm_II_Day_10_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Top_Interview_150_Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00 +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position/Solution.cs)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_I_Day_1_Binary_Search, Binary_Search_I_Day_2, Top_Interview_150_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 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/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_5, Top_Interview_150_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_11, Level_2_Day_8_Binary_Search, Udemy_Binary_Search, Top_Interview_150_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0032 |[Longest Valid Parentheses](LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/Solution.cs)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Stack, Big_O_Time_O(n)_Space_O(1) | 2 | 94.56 +| 0031 |[Next Permutation](LeetCodeNet/G0001_0100/S0031_next_permutation/Solution.cs)| Medium | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/Solution.cs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_13_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 +| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/Solution.cs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_12_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0023 |[Merge k Sorted Lists](LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Top_Interview_150_Divide_and_Conquer, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 3 | 97.54 +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Top_Interview_150_Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Data_Structure_I_Day_7_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00 +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Data_Structure_I_Day_9_Stack_Queue, Udemy_Strings, Top_Interview_150_Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 82.01 +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 +| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Top_Interview_150_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_1_Array, Algorithm_II_Day_3_Two_Pointers, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 34 | 76.14 +| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Top_Interview_150_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 99.97 +| 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching/Solution.cs)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 99.81 +| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number/Solution.cs)| Easy | Math, Udemy_Integers, Top_Interview_150_Math | 1 | 99.90 +| 0008 |[String to Integer (atoi)](LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/Solution.cs)| Medium | Top_Interview_Questions, String | 0 | 100.00 +| 0007 |[Reverse Integer](LeetCodeNet/G0001_0100/S0007_reverse_integer/Solution.cs)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 14 | 99.26 +| 0006 |[Zigzag Conversion](LeetCodeNet/G0001_0100/S0006_zigzag_conversion/Solution.cs)| Medium | String, Top_Interview_150_Array/String | 3 | 95.39 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Data_Structure_II_Day_9_String, Algorithm_II_Day_14_Dynamic_Programming, Dynamic_Programming_I_Day_17, Udemy_Strings, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(n)_Space_O(n) | 7 | 95.82 +| 0004 |[Median of Two Sorted Arrays](LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/Solution.cs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Top_Interview_150_Binary_Search, Big_O_Time_O(log(min(N,M)))_Space_O(1), AI_can_be_used_to_solve_the_task | 0 | 100.00 +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Algorithm_I_Day_6_Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Udemy_Strings, Top_Interview_150_Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.84 +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers/Solution.cs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15, Top_Interview_150_Linked_List, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 91.39 +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum/Solution.cs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays, Top_Interview_150_Hashmap, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 98.51 ## Contributing Your ideas/fixes/algorithms are more than welcome! 1. Fork this repo -2. Clone your forked repo (`git clone https://github.com/YOUR_GITHUB_USERNAME/LeetCode-in-Csharp.git`) onto your local machine +2. Clone your forked repo (`git clone https://github.com/YOUR_GITHUB_USERNAME/LeetCode-in-Net.git`) onto your local machine 3. `cd` into your cloned directory, create your feature branch (`git checkout -b my-awesome-fix`) 4. `git add` your desired changes to this repo 5. Commit your changes (`git commit -m 'Added some awesome features/fixes'`)