From 571f5b2d18bfcf1b23f7e1116794bb20bf5587f5 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:27:28 +0300 Subject: [PATCH 1/7] Added tasks 392-918 --- .../S0392_is_subsequence/SolutionTest.cs | 17 ++++ .../S0399_evaluate_division/SolutionTest.cs | 61 +++++++++++++ .../S0427_construct_quad_tree/SolutionTest.cs | 32 +++++++ .../SolutionTest.cs | 31 +++++++ .../SolutionTest.cs | 56 ++++++++++++ .../G0501_0600/S0502_ipo/SolutionTest.cs | 15 ++++ .../SolutionTest.cs | 21 +++++ .../SolutionTest.cs | 50 +++++++++++ .../S0909_snakes_and_ladders/SolutionTest.cs | 26 ++++++ .../SolutionTest.cs | 22 +++++ .../S0392_is_subsequence/Solution.cs | 28 ++++++ .../G0301_0400/S0392_is_subsequence/readme.md | 27 ++++++ .../S0399_evaluate_division/Solution.cs | 66 ++++++++++++++ .../S0399_evaluate_division/readme.md | 49 +++++++++++ .../S0427_construct_quad_tree/Solution.cs | 86 +++++++++++++++++++ .../S0427_construct_quad_tree/readme.md | 78 +++++++++++++++++ .../Solution.cs | 54 ++++++++++++ .../S0433_minimum_genetic_mutation/readme.md | 41 +++++++++ .../Solution.cs | 47 ++++++++++ .../readme.md | 47 ++++++++++ LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs | 46 ++++++++++ LeetCodeNet/G0501_0600/S0502_ipo/readme.md | 47 ++++++++++ .../Solution.cs | 36 ++++++++ .../readme.md | 28 ++++++ .../Solution.cs | 67 +++++++++++++++ .../readme.md | 26 ++++++ .../S0909_snakes_and_ladders/Solution.cs | 83 ++++++++++++++++++ .../S0909_snakes_and_ladders/readme.md | 55 ++++++++++++ .../Solution.cs | 42 +++++++++ .../readme.md | 39 +++++++++ README.md | 25 ++++++ 31 files changed, 1348 insertions(+) create mode 100644 LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0401_0500/S0427_construct_quad_tree/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0401_0500/S0433_minimum_genetic_mutation/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0501_0600/S0502_ipo/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs create mode 100644 LeetCodeNet.Tests/G0901_1000/S0918_maximum_sum_circular_subarray/SolutionTest.cs create mode 100644 LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs create mode 100644 LeetCodeNet/G0301_0400/S0392_is_subsequence/readme.md create mode 100644 LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs create mode 100644 LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md create mode 100644 LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs create mode 100644 LeetCodeNet/G0401_0500/S0427_construct_quad_tree/readme.md create mode 100644 LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs create mode 100644 LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/readme.md create mode 100644 LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs create mode 100644 LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/readme.md create mode 100644 LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs create mode 100644 LeetCodeNet/G0501_0600/S0502_ipo/readme.md create mode 100644 LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs create mode 100644 LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md create mode 100644 LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs create mode 100644 LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md create mode 100644 LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/Solution.cs create mode 100644 LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/readme.md create mode 100644 LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs create mode 100644 LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/readme.md diff --git a/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs new file mode 100644 index 0000000..dacad31 --- /dev/null +++ b/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs @@ -0,0 +1,17 @@ +namespace LeetCodeNet.G0301_0400.S0392_is_subsequence { + +using System; +using Xunit; + +public class SolutionTest { + [Fact] + public void IsSubsequence() { + Assert.Equal(true, new Solution().IsSubsequence("abc", "ahbgdc")); + } + + [Fact] + public void IsSubsequence2Test() { + Assert.Equal(false, new Solution().IsSubsequence("axc", "ahbgdc")); + } +} +} diff --git a/LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs new file mode 100644 index 0000000..4cb9234 --- /dev/null +++ b/LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs @@ -0,0 +1,61 @@ +namespace LeetCodeNet.G0301_0400.S0399_evaluate_division { + +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +public static class ArrayUtils { + public static IList> GetLists(string[][] array) { + var result = new List>(); + foreach (var innerArray in array) { + result.Add(innerArray.ToList()); + } + return result; + } +} + +public class SolutionTest { + private const double Tolerance = 0.00001; + + [Fact] + public void CalcEquation() { + IList> equations = ArrayUtils.GetLists(new string[][] {new string[] {"a", "b"}, new string[] {"b", "c"}}); + double[] values = new double[] {2.0, 3.0}; + IList> queries = + ArrayUtils.GetLists( + new string[][] { + new string[] {"a", "c"}, new string[] {"b", "a"}, new string[] {"a", "e"}, new string[] {"a", "a"}, new string[] {"x", "x"} + }); + double[] expected = {6.00000, 0.50000, -1.00000, 1.00000, -1.00000}; + // For comparing double arrays with precision, use a loop or a custom assertion method + Assert.Equal(expected, new Solution().CalcEquation(equations, values, queries), Tolerance); + } + + [Fact] + public void CalcEquation2() { + IList> equations = + ArrayUtils.GetLists(new string[][] {new string[] {"a", "b"}, new string[] {"b", "c"}, new string[] {"bc", "cd"}}); + double[] values = new double[] {1.5, 2.5, 5.0}; + IList> queries = + ArrayUtils.GetLists( + new string[][] {new string[] {"a", "c"}, new string[] {"c", "b"}, new string[] {"bc", "cd"}, new string[] {"cd", "bc"}}); + double[] expected = {3.75000, 0.40000, 5.00000, 0.20000}; + Assert.Equal(expected, new Solution().CalcEquation(equations, values, queries), Tolerance); + } + + [Fact] + public void CalcEquation3() { + // Direct initialization of List> + IList> equations = new List> { + new List {"a", "b"} + }; + double[] values = new double[] {0.5}; + IList> queries = + ArrayUtils.GetLists( + new string[][] {new string[] {"a", "b"}, new string[] {"b", "a"}, new string[] {"a", "c"}, new string[] {"x", "y"}}); + double[] expected = {0.50000, 2.00000, -1.00000, -1.00000}; + Assert.Equal(expected, new Solution().CalcEquation(equations, values, queries), Tolerance); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0427_construct_quad_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0427_construct_quad_tree/SolutionTest.cs new file mode 100644 index 0000000..31871b9 --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0427_construct_quad_tree/SolutionTest.cs @@ -0,0 +1,32 @@ +namespace LeetCodeNet.G0401_0500.S0427_construct_quad_tree { + +using System; +using Xunit; + +public class SolutionTest { + [Fact] + public void Construct() { + string expectedOutput = "[0,1][1,0][1,1][1,1][1,0]"; + Assert.Equal(expectedOutput, new Solution().Construct(new int[][] {new int[] {0, 1}, new int[] {1, 0}}).ToString()); + } + + [Fact] + public void Construct2() { + string expectedOutput = "[0,1][1,1][0,1][1,1][1,0]"; + Assert.Equal(expectedOutput, + new Solution() + .Construct( + new int[][] { + new int[] {1, 1, 1, 1, 0, 0, 0, 0}, + new int[] {1, 1, 1, 1, 0, 0, 0, 0}, + new int[] {1, 1, 1, 1, 1, 1, 1, 1}, + new int[] {1, 1, 1, 1, 1, 1, 1, 1}, + new int[] {1, 1, 1, 1, 0, 0, 0, 0}, + new int[] {1, 1, 1, 1, 0, 0, 0, 0}, + new int[] {1, 1, 1, 1, 0, 0, 0, 0}, + new int[] {1, 1, 1, 1, 0, 0, 0, 0} + }) + .ToString()); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0433_minimum_genetic_mutation/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0433_minimum_genetic_mutation/SolutionTest.cs new file mode 100644 index 0000000..05d1a88 --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0433_minimum_genetic_mutation/SolutionTest.cs @@ -0,0 +1,31 @@ +namespace LeetCodeNet.G0401_0500.S0433_minimum_genetic_mutation { + +using Xunit; + +public class SolutionTest { + [Fact] + public void MinMutation() { + Assert.Equal(1, new Solution().MinMutation("AACCGGTT", "AACCGGTA", new string[] {"AACCGGTA"})); + } + + [Fact] + public void MinMutation2() { + Assert.Equal(2, + new Solution() + .MinMutation( + "AACCGGTT", + "AAACGGTA", + new string[] {"AACCGGTA", "AACCGCTA", "AAACGGTA"})); + } + + [Fact] + public void MinMutation3() { + Assert.Equal(3, + new Solution() + .MinMutation( + "AAAAACCC", + "AACCCCCC", + new string[] {"AAAACCCC", "AAACCCCC", "AACCCCCC"})); + } +} +} diff --git a/LeetCodeNet.Tests/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/SolutionTest.cs b/LeetCodeNet.Tests/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/SolutionTest.cs new file mode 100644 index 0000000..9682a52 --- /dev/null +++ b/LeetCodeNet.Tests/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/SolutionTest.cs @@ -0,0 +1,56 @@ +namespace LeetCodeNet.G0401_0500.S0452_minimum_number_of_arrows_to_burst_balloons { + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Xunit; + +public static class CommonUtils { + public static int[][] ConvertLeetCode2DArrayInputToArray(string input) { + string[] rawPairs = input.TrimStart('[').TrimEnd(']').Split("],[", StringSplitOptions.RemoveEmptyEntries); + List result = new List(); + foreach (string pair in rawPairs) { + // Split each pair by comma + string[] numbers = pair.Split(','); + if (numbers.Length == 2) { + int[] intArray = new int[2]; + if (int.TryParse(numbers[0], out intArray[0]) && int.TryParse(numbers[1], out intArray[1])) { + result.Add(intArray); + } else { + throw new FormatException($"Invalid number format in pair: {pair}"); + } + } else { + throw new FormatException($"Invalid pair format: {pair}"); + } + } + return result.ToArray(); + } +} + +public class SolutionTest { + [Fact] + public void FindMinArrowShots() { + int[][] points = + CommonUtils.ConvertLeetCode2DArrayInputToArray( + "[10,16],[2,8],[1,6],[7,12]"); + Assert.Equal(2, new Solution().FindMinArrowShots(points)); + } + + [Fact] + public void FindMinArrowShots2() { + int[][] points = + CommonUtils.ConvertLeetCode2DArrayInputToArray( + "[1,2],[3,4],[5,6],[7,8]"); + Assert.Equal(4, new Solution().FindMinArrowShots(points)); + } + + [Fact] + public void FindMinArrowShots3() { + int[][] points = + CommonUtils.ConvertLeetCode2DArrayInputToArray( + "[1,2],[2,3],[3,4],[4,5]"); + Assert.Equal(2, new Solution().FindMinArrowShots(points)); + } +} +} diff --git a/LeetCodeNet.Tests/G0501_0600/S0502_ipo/SolutionTest.cs b/LeetCodeNet.Tests/G0501_0600/S0502_ipo/SolutionTest.cs new file mode 100644 index 0000000..0807705 --- /dev/null +++ b/LeetCodeNet.Tests/G0501_0600/S0502_ipo/SolutionTest.cs @@ -0,0 +1,15 @@ +namespace LeetCodeNet.G0501_0600.S0502_ipo { + +using System; +using Xunit; + +public class SolutionTest { + [Fact] public void FindMaximizedCapital() { + Assert.Equal(4, new Solution().FindMaximizedCapital(2, 0, new int[] {1, 2, 3}, new int[] {0, 1, 1})); + } + + [Fact] public void FindMaximizedCapital2() { + Assert.Equal(6, new Solution().FindMaximizedCapital(3, 0, new int[] {1, 2, 3}, new int[] {0, 1, 2})); + } +} +} diff --git a/LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs b/LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs new file mode 100644 index 0000000..92b5dc4 --- /dev/null +++ b/LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs @@ -0,0 +1,21 @@ +namespace LeetCodeNet.G0501_0600.S0530_minimum_absolute_difference_in_bst { + +using System; +using LeetCodeNet.Com_github_leetcode; +using Xunit; + +public class SolutionTest { + [Fact] + public void GetMinimumDifference() { + TreeNode treeNode = TreeUtils.ConstructBinaryTree(new List {4, 2, 6, 1, 3}); + Assert.Equal(1, new Solution().GetMinimumDifference(treeNode)); + } + + [Fact] + public void GetMinimumDifference2() { + TreeNode treeNode = + TreeUtils.ConstructBinaryTree(new List {1, 0, 48, null, null, 12, 49}); + Assert.Equal(1, new Solution().GetMinimumDifference(treeNode)); + } +} +} diff --git a/LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs new file mode 100644 index 0000000..e2c8ec2 --- /dev/null +++ b/LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs @@ -0,0 +1,50 @@ +namespace LeetCodeNet.G0601_0700.S0637_average_of_levels_in_binary_tree { + +using System; +using LeetCodeNet.Com_github_leetcode; +using Xunit; + +public class SolutionTest { + [Fact] + public void AverageOfLevels() { + TreeNode treeNode = TreeNode.Create(new List {3, 9, 20, null, null, 15, 7}); + Assert.Equal(new List {3.00000, 14.50000, 11.00000}, new Solution().AverageOfLevels(treeNode), + new DoubleListComparer(0.00001)); + } + + [Fact] public void AverageOfLevels2() { + TreeNode treeNode = TreeNode.Create(new List {3, 9, 20, 15, 7}); + Assert.Equal(new List {3.00000, 14.50000, 11.00000}, new Solution().AverageOfLevels(treeNode), + new DoubleListComparer(0.00001)); + } +} + +public class DoubleListComparer : IEqualityComparer> { + private readonly double _tolerance; + + public DoubleListComparer(double tolerance) { + _tolerance = tolerance; + } + + public bool Equals(IList x, IList y) { + if (ReferenceEquals(x, y)) return true; + if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; + if (x.Count != y.Count) return false; + + for (int i = 0; i < x.Count; i++) { + if (Math.Abs(x[i] - y[i]) > _tolerance) { + return false; + } + } + return true; + } + + public int GetHashCode(IList obj) { + int hash = 17; + foreach (var d in obj) { + hash = hash * 31 + d.GetHashCode(); + } + return hash; + } +} +} diff --git a/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs b/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs new file mode 100644 index 0000000..aa34078 --- /dev/null +++ b/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs @@ -0,0 +1,26 @@ +namespace LeetCodeNet.G0901_1000.S0909_snakes_and_ladders { + +using System; +using Xunit; + +public class SolutionTest { + [Fact] + public void SnakesAndLadders() { + Assert.Equal(4, + new Solution() + .SnakesAndLadders( + new int[][] { + new int[] {-1, -1, -1, -1, -1, -1}, + new int[] {-1, -1, -1, -1, -1, -1}, + new int[] {-1, -1, -1, -1, -1, -1}, + new int[] {-1, 35, -1, -1, 13, -1}, + new int[] {-1, -1, -1, -1, -1, -1}, + new int[] {-1, 15, -1, -1, -1, -1} + })); + } + + [Fact] + public void SnakesAndLadders2() { + Assert.Equal(1, new Solution().SnakesAndLadders(new int[][] {new int[] {-1, -1}, new int[] {-1, 3}})); + } +} diff --git a/LeetCodeNet.Tests/G0901_1000/S0918_maximum_sum_circular_subarray/SolutionTest.cs b/LeetCodeNet.Tests/G0901_1000/S0918_maximum_sum_circular_subarray/SolutionTest.cs new file mode 100644 index 0000000..6dbd442 --- /dev/null +++ b/LeetCodeNet.Tests/G0901_1000/S0918_maximum_sum_circular_subarray/SolutionTest.cs @@ -0,0 +1,22 @@ +namespace LeetCodeNet.G0901_1000.S0918_maximum_sum_circular_subarray { + +using System; +using Xunit; + +public class SolutionTest { + [Fact] + public void MaxSubarraySumCircular() { + Assert.Equal(3, new Solution().MaxSubarraySumCircular(new int[] {1, -2, 3, -2})); + } + + [Fact] + public void MaxSubarraySumCircular2() { + Assert.Equal(10, new Solution().MaxSubarraySumCircular(new int[] {5, -3, 5})); + } + + [Fact] + public void MaxSubarraySumCircular3() { + Assert.Equal(-2, new Solution().MaxSubarraySumCircular(new int[] {-3, -2, -3})); + } +} +} diff --git a/LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs b/LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs new file mode 100644 index 0000000..8d0ffa8 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs @@ -0,0 +1,28 @@ +namespace LeetCodeNet.G0301_0400.S0392_is_subsequence { + +// #Easy #String #Dynamic_Programming #Two_Pointers #LeetCode_75_Two_Pointers +// #Dynamic_Programming_I_Day_19 #Level_1_Day_2_String #Udemy_Two_Pointers +// #Top_Interview_150_Two_Pointers #2025_07_18_Time_0_ms_(100.00%)_Space_41.56_MB_(66.80%) + +public class Solution { + public bool IsSubsequence(string s, string t) { + int i = 0; + int j = 0; + int n = t.Length; + int m = s.Length; + if (m == 0) { + return true; + } + while (j < n) { + if (s[i] == t[j]) { + i++; + if (i == m) { + return true; + } + } + j++; + } + return false; + } +} +} diff --git a/LeetCodeNet/G0301_0400/S0392_is_subsequence/readme.md b/LeetCodeNet/G0301_0400/S0392_is_subsequence/readme.md new file mode 100644 index 0000000..a002fe0 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0392_is_subsequence/readme.md @@ -0,0 +1,27 @@ +392\. Is Subsequence + +Easy + +Given two strings `s` and `t`, return `true` _if_ `s` _is a **subsequence** of_ `t`_, or_ `false` _otherwise_. + +A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of `"abcde"` while `"aec"` is not). + +**Example 1:** + +**Input:** s = "abc", t = "ahbgdc" + +**Output:** true + +**Example 2:** + +**Input:** s = "axc", t = "ahbgdc" + +**Output:** false + +**Constraints:** + +* `0 <= s.length <= 100` +* 0 <= t.length <= 104 +* `s` and `t` consist only of lowercase English letters. + +**Follow up:** Suppose there are lots of incoming `s`, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if `t` has its subsequence. In this scenario, how would you change your code? \ No newline at end of file diff --git a/LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs b/LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs new file mode 100644 index 0000000..2bc8f7b --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs @@ -0,0 +1,66 @@ +namespace LeetCodeNet.G0301_0400.S0399_evaluate_division { + +// #Medium #Array #Depth_First_Search #Breadth_First_Search #Graph #Union_Find #Shortest_Path +// #LeetCode_75_Graphs/DFS #Top_Interview_150_Graph_General +// #2025_07_18_Time_3_ms_(66.56%)_Space_48.00_MB_(43.48%) + +using System; +using System.Collections.Generic; + +public class Solution { + private Dictionary root; + private Dictionary rate; + + public double[] CalcEquation( + IList> equations, double[] values, IList> queries) { + root = new Dictionary(); + rate = new Dictionary(); + int n = equations.Count; + foreach (var equation in equations) { + string x = equation[0]; + string y = equation[1]; + root[x] = x; // In C#, Dictionary uses [] for put/get + root[y] = y; + rate[x] = 1.0; + rate[y] = 1.0; + } + for (int i = 0; i < n; ++i) { + string x = equations[i][0]; + string y = equations[i][1]; + union(x, y, values[i]); + } + double[] result = new double[queries.Count]; + for (int i = 0; i < queries.Count; ++i) { + string x = queries[i][0]; + string y = queries[i][1]; + if (!root.ContainsKey(x) || !root.ContainsKey(y)) { + result[i] = -1; + continue; + } + string rootX = findRoot(x, x, 1.0); + string rootY = findRoot(y, y, 1.0); + // In C#, string comparison uses .Equals() + result[i] = rootX.Equals(rootY) ? rate[x] / rate[y] : -1.0; + } + return result; + } + + private void union(string x, string y, double v) { + string rootX = findRoot(x, x, 1.0); + string rootY = findRoot(y, y, 1.0); + root[rootX] = rootY; + double r1 = rate[x]; + double r2 = rate[y]; + rate[rootX] = v * r2 / r1; + } + + private string findRoot(string originalX, string x, double r) { + if (root[x].Equals(x)) { // In C#, Dictionary uses [] for get + root[originalX] = x; + rate[originalX] = r * rate[x]; + return x; + } + return findRoot(originalX, root[x], r * rate[x]); + } +} +} diff --git a/LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md b/LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md new file mode 100644 index 0000000..18a83c5 --- /dev/null +++ b/LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md @@ -0,0 +1,49 @@ +399\. Evaluate Division + +Medium + +You are given an array of variable pairs `equations` and an array of real numbers `values`, where equations[i] = [Ai, Bi] and `values[i]` represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable. + +You are also given some `queries`, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?. + +Return _the answers to all queries_. If a single answer cannot be determined, return `-1.0`. + +**Note:** The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction. + +**Example 1:** + +**Input:** equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] + +**Output:** [6.00000,0.50000,-1.00000,1.00000,-1.00000] + +**Explanation:** + +Given: _a / b = 2.0_, _b / c = 3.0_ + +queries are: _a / c = ?_, _b / a = ?_, _a / e = ?_, _a / a = ?_, _x / x = ?_ + +return: [6.0, 0.5, -1.0, 1.0, -1.0 ] + +**Example 2:** + +**Input:** equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]] + +**Output:** [3.75000,0.40000,5.00000,0.20000] + +**Example 3:** + +**Input:** equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]] + +**Output:** [0.50000,2.00000,-1.00000,-1.00000] + +**Constraints:** + +* `1 <= equations.length <= 20` +* `equations[i].length == 2` +* 1 <= Ai.length, Bi.length <= 5 +* `values.length == equations.length` +* `0.0 < values[i] <= 20.0` +* `1 <= queries.length <= 20` +* `queries[i].length == 2` +* 1 <= Cj.length, Dj.length <= 5 +* Ai, Bi, Cj, Dj consist of lower case English letters and digits. \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs new file mode 100644 index 0000000..9b824a4 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs @@ -0,0 +1,86 @@ +namespace LeetCodeNet.G0401_0500.S0427_construct_quad_tree { + +// #Medium #Array #Tree #Matrix #Divide_and_Conquer #Top_Interview_150_Divide_and_Conquer +// #2025_07_18_Time_91_ms_(66.88%)_Space_47.25_MB_(80.00%) + +/* +// Definition for a QuadTree node. +public class Node { + public bool val; + public bool isLeaf; + public Node topLeft; + public Node topRight; + public Node bottomLeft; + public Node bottomRight; + + public Node() { + val = false; + isLeaf = false; + topLeft = null; + topRight = null; + bottomLeft = null; + bottomRight = null; + } + + public Node(bool _val, bool _isLeaf) { + val = _val; + isLeaf = _isLeaf; + topLeft = null; + topRight = null; + bottomLeft = null; + bottomRight = null; + } + + public Node(bool _val,bool _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) { + val = _val; + isLeaf = _isLeaf; + topLeft = _topLeft; + topRight = _topRight; + bottomLeft = _bottomLeft; + bottomRight = _bottomRight; + } +} +*/ +public class Solution { + public Node Construct(int[][] grid) { + return OptimizedDfs(grid, 0, 0, grid.Length); + } + + private Node OptimizedDfs(int[][] grid, int rowStart, int colStart, int len) { + int zeroCount = 0; + int oneCount = 0; + for (int row = rowStart; row < rowStart + len; row++) { + bool isBreak = false; + for (int col = colStart; col < colStart + len; col++) { + if (grid[row][col] == 0) { + zeroCount++; + } else { + oneCount++; + } + if (oneCount > 0 && zeroCount > 0) { + // We really no need to scan all. + // Once we know there are both 0 and 1 then we can break. + isBreak = true; + break; + } + } + if (isBreak) { + break; + } + } + if (oneCount > 0 && zeroCount > 0) { + int midLen = len / 2; + Node topLeft = OptimizedDfs(grid, rowStart, colStart, midLen); + Node topRight = OptimizedDfs(grid, rowStart, colStart + midLen, midLen); + Node bottomLeft = OptimizedDfs(grid, rowStart + midLen, colStart, midLen); + Node bottomRight = OptimizedDfs(grid, rowStart + midLen, colStart + midLen, midLen); + bool isLeaf = false; + return new Node(true, isLeaf, topLeft, topRight, bottomLeft, bottomRight); + } else { + bool resultVal = oneCount > 0; + bool isLeaf = true; + return new Node(resultVal, isLeaf); + } + } +} +} diff --git a/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/readme.md b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/readme.md new file mode 100644 index 0000000..9e9dd3d --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/readme.md @@ -0,0 +1,78 @@ +427\. Construct Quad Tree + +Medium + +Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent the `grid` with a Quad-Tree. + +Return _the root of the Quad-Tree_ representing the `grid`. + +Notice that you can assign the value of a node to **True** or **False** when `isLeaf` is **False**, and both are **accepted** in the answer. + +A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes: + +* `val`: True if the node represents a grid of 1's or False if the node represents a grid of 0's. +* `isLeaf`: True if the node is leaf node on the tree or False if the node has the four children. +``` + class Node { + public boolean val; + public boolean isLeaf; + public Node topLeft; + public Node topRight; + public Node bottomLeft; + public Node bottomRight; + } +``` +We can construct a Quad-Tree from a two-dimensional area using the following steps: + +1. If the current grid has the same value (i.e all `1's` or all `0's`) set `isLeaf` True and set `val` to the value of the grid and set the four children to Null and stop. +2. If the current grid has different values, set `isLeaf` to False and set `val` to any value and divide the current grid into four sub-grids as shown in the photo. +3. Recurse for each of the children with the proper sub-grid. + +![](https://assets.leetcode.com/uploads/2020/02/11/new_top.png) + +If you want to know more about the Quad-Tree, you can refer to the [wiki](https://en.wikipedia.org/wiki/Quadtree). + +**Quad-Tree format:** + +The output represents the serialized format of a Quad-Tree using level order traversal, where `null` signifies a path terminator where no node exists below. + +It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list `[isLeaf, val]`. + +If the value of `isLeaf` or `val` is True we represent it as **1** in the list `[isLeaf, val]` and if the value of `isLeaf` or `val` is False we represent it as **0**. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/02/11/grid1.png) + +**Input:** grid = [[0,1],[1,0]] + +**Output:** [[0,1],[1,0],[1,1],[1,1],[1,0]] + +**Explanation:** + + The explanation of this example is shown below: + Notice that 0 represnts False and 1 represents True in the photo representing the Quad-Tree. + +![](https://assets.leetcode.com/uploads/2020/02/12/e1tree.png) + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/02/12/e2mat.png) + +**Input:** grid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]] + +**Output:** [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]] + +**Explanation:** + + All values in the grid are not the same. We divide the grid into four sub-grids. + The topLeft, bottomLeft and bottomRight each has the same value. + The topRight have different values so we divide it into 4 sub-grids where each has the same value. + Explanation is shown in the photo below: + +![](https://assets.leetcode.com/uploads/2020/02/12/e2tree.png) + +**Constraints:** + +* `n == grid.length == grid[i].length` +* n == 2x where `0 <= x <= 6` diff --git a/LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs b/LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs new file mode 100644 index 0000000..b4d7254 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs @@ -0,0 +1,54 @@ +namespace LeetCodeNet.G0401_0500.S0433_minimum_genetic_mutation { + +// #Medium #String #Hash_Table #Breadth_First_Search #Graph_Theory_I_Day_12_Breadth_First_Search +// #Top_Interview_150_Graph_BFS #2025_07_18_Time_1_ms_(78.46%)_Space_41.13_MB_(73.33%) + +using System; +using System.Collections.Generic; + +public class Solution { + private IList IsInBank(ISet set, string cur) { + List res = new List(); + foreach (string each in set) { + int diff = 0; + for (int i = 0; i < each.Length; i++) { + if (each[i] != cur[i]) { + diff++; + if (diff > 1) { + break; + } + } + } + if (diff == 1) { + res.Add(each); + } + } + return res; + } + + public int MinMutation(string start, string end, string[] bank) { + ISet set = new HashSet(); + foreach (string s in bank) { + set.Add(s); + } + Queue queue = new Queue(); + queue.Enqueue(start); + int step = 0; + while (queue.Count > 0) { + int curSize = queue.Count; + while (curSize-- > 0) { + string cur = queue.Dequeue(); + if (cur.Equals(end)) { + return step; + } + foreach (string next in IsInBank(set, cur)) { + queue.Enqueue(next); + set.Remove(next); + } + } + step++; + } + return -1; + } +} +} diff --git a/LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/readme.md b/LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/readme.md new file mode 100644 index 0000000..fa7b381 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/readme.md @@ -0,0 +1,41 @@ +433\. Minimum Genetic Mutation + +Medium + +A gene string can be represented by an 8-character long string, with choices from `'A'`, `'C'`, `'G'`, and `'T'`. + +Suppose we need to investigate a mutation from a gene string `start` to a gene string `end` where one mutation is defined as one single character changed in the gene string. + +* For example, `"AACCGGTT" --> "AACCGGTA"` is one mutation. + +There is also a gene bank `bank` that records all the valid gene mutations. A gene must be in `bank` to make it a valid gene string. + +Given the two gene strings `start` and `end` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `start` _to_ `end`. If there is no such a mutation, return `-1`. + +Note that the starting point is assumed to be valid, so it might not be included in the bank. + +**Example 1:** + +**Input:** start = "AACCGGTT", end = "AACCGGTA", bank = ["AACCGGTA"] + +**Output:** 1 + +**Example 2:** + +**Input:** start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"] + +**Output:** 2 + +**Example 3:** + +**Input:** start = "AAAAACCC", end = "AACCCCCC", bank = ["AAAACCCC","AAACCCCC","AACCCCCC"] + +**Output:** 3 + +**Constraints:** + +* `start.length == 8` +* `end.length == 8` +* `0 <= bank.length <= 10` +* `bank[i].length == 8` +* `start`, `end`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`. \ No newline at end of file diff --git a/LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs b/LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs new file mode 100644 index 0000000..b9802f2 --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs @@ -0,0 +1,47 @@ +namespace LeetCodeNet.G0401_0500.S0452_minimum_number_of_arrows_to_burst_balloons { + +// #Medium #Array #Sorting #Greedy #LeetCode_75_Intervals #Top_Interview_150_Intervals +// #2025_07_18_Time_51_ms_(49.35%)_Space_78.67_MB_(21.94%) + +using System; +using System.Linq; + +public class Solution { + /* + * I'm glad to have come up with this solution on my own on 10/13/2021: + * we'll have to sort the + * balloons by its ending points, a counter case to this is below: + * {{0, 6}, {0, 9}, {7, 8}} + * if we sort by starting points, then it becomes: + * {0, 6}, {0, 9}, {7, 8} + * this way, if we shoot 9, + * {0, 6} won't be burst however, if we sort by ending points, then it becomes: + * {0, 6}, {7, 8}, {0, 9}, then we shoot at 6, then at 8, this gives us the result of bursting all balloons. + */ + public int FindMinArrowShots(int[][] points) { + if (points == null || points.Length == 0) { + return 0; + } + // Sort by the ending point + Array.Sort(points, (a, b) => { + // C# does not have Integer.compare. + // When dealing with int, direct comparison is usually fine. + // For long, careful casting or using Comparer.Default.Compare might be needed. + // Here, a[1] and b[1] are int, so direct comparison works. + return a[1].CompareTo(b[1]); + }); + int minArrows = 1; + // Use long to avoid potential overflow if points[1] could be int.MaxValue + long end = points[0][1]; + for (int i = 1; i < points.Length; i++) { + // If the current balloon starts after the last arrow's effective end, + // we need a new arrow. + if (points[i][0] > end) { + minArrows++; + end = points[i][1]; + } + } + return minArrows; + } +} +} diff --git a/LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/readme.md b/LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/readme.md new file mode 100644 index 0000000..eb0a22a --- /dev/null +++ b/LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/readme.md @@ -0,0 +1,47 @@ +452\. Minimum Number of Arrows to Burst Balloons + +Medium + +There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array `points` where points[i] = [xstart, xend] denotes a balloon whose **horizontal diameter** stretches between xstart and xend. You do not know the exact y-coordinates of the balloons. + +Arrows can be shot up **directly vertically** (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is **burst** by an arrow shot at `x` if xstart <= x <= xend. There is **no limit** to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path. + +Given the array `points`, return _the **minimum** number of arrows that must be shot to burst all balloons_. + +**Example 1:** + +**Input:** points = [[10,16],[2,8],[1,6],[7,12]] + +**Output:** 2 + +**Explanation:** The balloons can be burst by 2 arrows: + +- Shoot an arrow at x = 6, bursting the balloons [2,8] and [1,6]. + +- Shoot an arrow at x = 11, bursting the balloons [10,16] and [7,12]. + +**Example 2:** + +**Input:** points = [[1,2],[3,4],[5,6],[7,8]] + +**Output:** 4 + +**Explanation:** One arrow needs to be shot for each balloon for a total of 4 arrows. + +**Example 3:** + +**Input:** points = [[1,2],[2,3],[3,4],[4,5]] + +**Output:** 2 + +**Explanation:** The balloons can be burst by 2 arrows: + +- Shoot an arrow at x = 2, bursting the balloons [1,2] and [2,3]. + +- Shoot an arrow at x = 4, bursting the balloons [3,4] and [4,5]. + +**Constraints:** + +* 1 <= points.length <= 105 +* `points[i].length == 2` +* -231 <= xstart < xend <= 231 - 1 \ No newline at end of file diff --git a/LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs b/LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs new file mode 100644 index 0000000..beb9ff0 --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs @@ -0,0 +1,46 @@ +namespace LeetCodeNet.G0501_0600.S0502_ipo { + +// #Hard #Array #Sorting #Greedy #Heap_Priority_Queue #Top_Interview_150_Heap +// #2025_07_18_Time_199_ms_(62.82%)_Space_89.82_MB_(10.25%) + +using System; +using System.Collections.Generic; + +public class Solution { + public int FindMaximizedCapital(int k, int w, int[] profits, int[] capital) { + // Min-heap for projects based on capital required + // TElement is int[] {profit, capital}, TPriority is capital (for min-heap) + // The comparer here compares the TPriority values (which are 'int'). + var minCapital = new PriorityQueue(); // Default comparer for int is min-heap + // Max-heap for projects based on profit + // TElement is int[] {profit, capital}, TPriority is profit (for max-heap) + // We need a custom comparer for TPriority 'int' to make it a max-heap. + // Compares priority values (profits) + var maxProfit = new PriorityQueue(Comparer.Create((p1, p2) => p2.CompareTo(p1))); + for (int i = 0; i < profits.Length; i++) { + if (w >= capital[i]) { + // Enqueue the project (int[]) with its profit as priority for the max-heap + maxProfit.Enqueue(new int[] { profits[i], capital[i] }, profits[i]); + } else { + // Enqueue the project (int[]) with its capital as priority for the min-heap + minCapital.Enqueue(new int[] { profits[i], capital[i] }, capital[i]); + } + } + int count = 0; + while (count < k && maxProfit.Count > 0) { + // Dequeue returns the element (int[]), not the priority + int[] temp = maxProfit.Dequeue(); + w += temp[0]; // Add profit to current capital + count++; + // Move projects from minCapital to maxProfit if current capital (w) is sufficient + // Peek() returns the element (int[]), not the priority. + while (minCapital.Count > 0 && minCapital.Peek()[1] <= w) { + int[] project = minCapital.Dequeue(); + // Enqueue the moved project with its profit as priority into maxProfit heap + maxProfit.Enqueue(project, project[0]); + } + } + return w; + } +} +} diff --git a/LeetCodeNet/G0501_0600/S0502_ipo/readme.md b/LeetCodeNet/G0501_0600/S0502_ipo/readme.md new file mode 100644 index 0000000..25b58de --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0502_ipo/readme.md @@ -0,0 +1,47 @@ +502\. IPO + +Hard + +Suppose LeetCode will start its **IPO** soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the **IPO**. Since it has limited resources, it can only finish at most `k` distinct projects before the **IPO**. Help LeetCode design the best way to maximize its total capital after finishing at most `k` distinct projects. + +You are given `n` projects where the ith project has a pure profit `profits[i]` and a minimum capital of `capital[i]` is needed to start it. + +Initially, you have `w` capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital. + +Pick a list of **at most** `k` distinct projects from given projects to **maximize your final capital**, and return _the final maximized capital_. + +The answer is guaranteed to fit in a 32-bit signed integer. + +**Example 1:** + +**Input:** k = 2, w = 0, profits = [1,2,3], capital = [0,1,1] + +**Output:** 4 + +**Explanation:** + +Since your initial capital is 0, you can only start the project indexed 0. + +After finishing it you will obtain profit 1 and your capital becomes 1. + +With capital 1, you can either start the project indexed 1 or the project indexed 2. + +Since you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital. + +Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4. + +**Example 2:** + +**Input:** k = 3, w = 0, profits = [1,2,3], capital = [0,1,2] + +**Output:** 6 + +**Constraints:** + +* 1 <= k <= 105 +* 0 <= w <= 109 +* `n == profits.length` +* `n == capital.length` +* 1 <= n <= 105 +* 0 <= profits[i] <= 104 +* 0 <= capital[i] <= 109 \ No newline at end of file diff --git a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs new file mode 100644 index 0000000..412f7ea --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs @@ -0,0 +1,36 @@ +namespace LeetCodeNet.G0501_0600.S0530_minimum_absolute_difference_in_bst { + +// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Binary_Search_Tree +// #Top_Interview_150_Binary_Search_Tree #2025_07_18_Time_0_ms_(100.00%)_Space_46.02_MB_(84.51%) + +using System; + +/** + * 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 ans = int.MaxValue; + private int prev = int.MaxValue; + + public int GetMinimumDifference(TreeNode root) { + if (root == null) { + return ans; + } + GetMinimumDifference(root.left); + ans = Math.Min(ans, Math.Abs(root.val - prev)); + prev = root.val; + GetMinimumDifference(root.right); + return ans; + } +} +} diff --git a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md new file mode 100644 index 0000000..2a52de1 --- /dev/null +++ b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md @@ -0,0 +1,28 @@ +530\. Minimum Absolute Difference in BST + +Easy + +Given the `root` of a Binary Search Tree (BST), return _the minimum absolute difference between the values of any two different nodes in the tree_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg) + +**Input:** root = [4,2,6,1,3] + +**Output:** 1 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg) + +**Input:** root = [1,0,48,null,null,12,49] + +**Output:** 1 + +**Constraints:** + +* The number of nodes in the tree is in the range [2, 104]. +* 0 <= Node.val <= 105 + +**Note:** This question is the same as 783: [https://leetcode.com/problems/minimum-distance-between-bst-nodes/](https://leetcode.com/problems/minimum-distance-between-bst-nodes/) \ No newline at end of file diff --git a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs new file mode 100644 index 0000000..434b440 --- /dev/null +++ b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs @@ -0,0 +1,67 @@ +namespace LeetCodeNet.G0601_0700.S0637_average_of_levels_in_binary_tree { + +// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree +// #Top_Interview_150_Binary_Tree_BFS #2025_07_18_Time_2_ms_(94.69%)_Space_51.17_MB_(31.56%) + +using System; +using System.Collections.Generic; + +/** + * 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 AverageOfLevels(TreeNode root) { + // Use Dictionary> to store (count, sum) for each level + // In C#, you can use a custom struct/class or Tuple for the pair. + // For simplicity, let's use double[] where [0] is count and [1] is sum. + IDictionary map = new Dictionary(); + Helper(root, map, 0); + IList result = new List(); + // Iterate through the dictionary values (which are the Double[] pairs) + // Since dictionary iteration order is not guaranteed, and we need levels in order, + // iterate up to the max level found. + int maxLevel = 0; + if (map.Count > 0) { + foreach (var key in map.Keys) { + if (key > maxLevel) { + maxLevel = key; + } + } + } + for (int i = 0; i <= maxLevel; i++) { + if (map.TryGetValue(i, out double[] pair)) { + double avg = pair[1] / pair[0]; + result.Add(avg); + } + } + return result; + } + + private void Helper(TreeNode root, IDictionary map, int level) { + if (root == null) { + return; + } + // Get or create the pair for the current level + if (!map.ContainsKey(level)) { + // Initialize count and sum + map[level] = new double[] {0.0, 0.0}; + } + // Increment count + map[level][0] += 1; + // Add value to sum + map[level][1] += root.val; + Helper(root.left, map, level + 1); + Helper(root.right, map, level + 1); + } +} +} diff --git a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md new file mode 100644 index 0000000..8bae0a4 --- /dev/null +++ b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md @@ -0,0 +1,26 @@ +637\. Average of Levels in Binary Tree + +Easy + +Given the `root` of a binary tree, return _the average value of the nodes on each level in the form of an array_. Answers within 10-5 of the actual answer will be accepted. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/09/avg1-tree.jpg) + +**Input:** root = [3,9,20,null,null,15,7] + +**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/09/avg2-tree.jpg) + +**Input:** root = [3,9,20,15,7] + +**Output:** [3.00000,14.50000,11.00000] + +**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/G0901_1000/S0909_snakes_and_ladders/Solution.cs b/LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/Solution.cs new file mode 100644 index 0000000..fb9534b --- /dev/null +++ b/LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/Solution.cs @@ -0,0 +1,83 @@ +namespace LeetCodeNet.G0901_1000.S0909_snakes_and_ladders { + +// #Medium #Array #Breadth_First_Search #Matrix #Top_Interview_150_Graph_BFS +// #2025_07_18_Time_6_ms_(72.69%)_Space_46.25_MB_(32.25%) + +using System; +using System.Collections.Generic; + +public class Solution { + private int size; + + public int SnakesAndLadders(int[][] board) { + Queue queue = new Queue(); + size = board.Length; + int target = size * size; + // Using 0-indexed for visited array, corresponding to labels 1 to target + bool[] visited = new bool[target]; + queue.Enqueue(1); + // Mark label 1 as visited (index 0) + visited[0] = true; + int step = 0; + while (queue.Count > 0) { + int queueSize = queue.Count; + for (int i = 0; i < queueSize; i++) { + int previousLabel = queue.Dequeue(); + if (previousLabel == target) { + return step; + } + // Simulate rolling a die (1 to 6) + for (int currentLabel = previousLabel + 1; + currentLabel <= Math.Min(target, previousLabel + 6); + currentLabel++) { + // currentLabel - 1 to map to 0-indexed array + if (visited[currentLabel - 1]) { + continue; + } + // Mark as visited + visited[currentLabel - 1] = true; + int[] position = IndexToPosition(currentLabel); + int boardValue = board[position[0]][position[1]]; + + if (boardValue == -1) { + queue.Enqueue(currentLabel); + } else { + queue.Enqueue(boardValue); + } + } + } + step++; + } + // Target not reachable + return -1; + } + + private int[] IndexToPosition(int index) { + // Adjust index to be 0-based for calculations related to 0 to size*size - 1 + int adjustedIndex = index - 1; + // Calculate row + // From bottom to top, so (size - 1) - (row based on adjustedIndex) + int row = size - 1 - adjustedIndex / size; + // Calculate column + int col; + // Check if the row is "snake" (even from bottom) or "ladder" (odd from bottom) + // (size - 1 - row) gives the 0-indexed row number from the top of the board. + // If (size - 1 - row) is even, it's a left-to-right row. + // If (size - 1 - row) is odd, it's a right-to-left row. + // The original Java code uses (this.size - vertical) % 2 == 1, + // which corresponds to (row from top of board) % 2 == 1, + // meaning if the row is odd (0-indexed from top), it's left-to-right + // If row from top is 0 (bottom row), 2, 4... then it's left to right. + // If row from top is 1, 3, 5... then it's right to left. + // (size - 1 - row) is equivalent to the number of rows from the bottom. + // (size - 1 - vertical) is a more direct translation from the Java code. + if ((size - 1 - row) % 2 == 0) { // Even row from top (0-indexed), moves right (left to right) + col = adjustedIndex % size; + } else { + // Odd row from top (0-indexed), moves left (right to left) + col = size - 1 - (adjustedIndex % size); + } + return new int[] {row, col}; + } +} +} diff --git a/LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/readme.md b/LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/readme.md new file mode 100644 index 0000000..f143794 --- /dev/null +++ b/LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/readme.md @@ -0,0 +1,55 @@ +909\. Snakes and Ladders + +Medium + +You are given an `n x n` integer matrix `board` where the cells are labeled from `1` to n2 in a [**Boustrophedon style**](https://en.wikipedia.org/wiki/Boustrophedon) starting from the bottom left of the board (i.e. `board[n - 1][0]`) and alternating direction each row. + +You start on square `1` of the board. In each move, starting from square `curr`, do the following: + +* Choose a destination square `next` with a label in the range [curr + 1, min(curr + 6, n2)]. + * This choice simulates the result of a standard **6-sided die roll**: i.e., there are always at most 6 destinations, regardless of the size of the board. +* If `next` has a snake or ladder, you **must** move to the destination of that snake or ladder. Otherwise, you move to `next`. +* The game ends when you reach the square n2. + +A board square on row `r` and column `c` has a snake or ladder if `board[r][c] != -1`. The destination of that snake or ladder is `board[r][c]`. Squares `1` and n2 do not have a snake or ladder. + +Note that you only take a snake or ladder at most once per move. If the destination to a snake or ladder is the start of another snake or ladder, you do **not** follow the subsequent snake or ladder. + +* For example, suppose the board is `[[-1,4],[-1,3]]`, and on the first move, your destination square is `2`. You follow the ladder to square `3`, but do **not** follow the subsequent ladder to `4`. + +Return _the least number of moves required to reach the square_ n2_. If it is not possible to reach the square, return_ `-1`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/09/23/snakes.png) + +**Input:** board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]] + +**Output:** 4 + +**Explanation:** + +In the beginning, you start at square 1 (at row 5, column 0). + +You decide to move to square 2 and must take the ladder to square 15. + +You then decide to move to square 17 and must take the snake to square 13. + +You then decide to move to square 14 and must take the ladder to square 35. + +You then decide to move to square 36, ending the game. + +This is the lowest possible number of moves to reach the last square, so return 4. + +**Example 2:** + +**Input:** board = [[-1,-1],[-1,3]] + +**Output:** 1 + +**Constraints:** + +* `n == board.length == board[i].length` +* `2 <= n <= 20` +* `grid[i][j]` is either `-1` or in the range [1, n2]. +* The squares labeled `1` and n2 do not have any ladders or snakes. \ No newline at end of file diff --git a/LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs b/LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs new file mode 100644 index 0000000..48a602a --- /dev/null +++ b/LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs @@ -0,0 +1,42 @@ +namespace LeetCodeNet.G0901_1000.S0918_maximum_sum_circular_subarray { + +// #Medium #Array #Dynamic_Programming #Divide_and_Conquer #Queue #Monotonic_Queue +// #Dynamic_Programming_I_Day_5 #Top_Interview_150_Kadane's_Algorithm +// #2025_07_18_Time_2_ms_(38.75%)_Space_52.96_MB_(71.25%) + +using System; +using System.Linq; + +public class Solution { + private int Kadane(int[] nums, int sign) { + int currSum = int.MinValue; + int maxSum = int.MinValue; + foreach (int i in nums) { + currSum = sign * i + Math.Max(currSum, 0); + maxSum = Math.Max(maxSum, currSum); + } + return maxSum; + } + + public int MaxSubarraySumCircular(int[] nums) { + if (nums.Length == 1) { + return nums[0]; + } + int sumOfArray = 0; + foreach (int i in nums) { + sumOfArray += i; + } + int maxSumSubarray = Kadane(nums, 1); + int minSumSubarray = Kadane(nums, -1) * -1; + // If all numbers are negative, minSumSubarray will be sumOfArray. + // In this case, the circular sum (sumOfArray - minSumSubarray) would be 0, + // which is incorrect if the actual answer is the largest negative number. + // The largest negative number would be captured by maxSumSubarray. + if (sumOfArray == minSumSubarray) { + return maxSumSubarray; + } else { + return Math.Max(maxSumSubarray, sumOfArray - minSumSubarray); + } + } +} +} diff --git a/LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/readme.md b/LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/readme.md new file mode 100644 index 0000000..f7a47fd --- /dev/null +++ b/LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/readme.md @@ -0,0 +1,39 @@ +918\. Maximum Sum Circular Subarray + +Medium + +Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`. + +A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` is `nums[(i - 1 + n) % n]`. + +A **subarray** may only include each element of the fixed buffer `nums` at most once. Formally, for a subarray `nums[i], nums[i + 1], ..., nums[j]`, there does not exist `i <= k1`, `k2 <= j` with `k1 % n == k2 % n`. + +**Example 1:** + +**Input:** nums = [1,-2,3,-2] + +**Output:** 3 + +**Explanation:** Subarray [3] has maximum sum 3. + +**Example 2:** + +**Input:** nums = [5,-3,5] + +**Output:** 10 + +**Explanation:** Subarray [5,5] has maximum sum 5 + 5 = 10. + +**Example 3:** + +**Input:** nums = [-3,-2,-3] + +**Output:** -2 + +**Explanation:** Subarray [-2] has maximum sum -2. + +**Constraints:** + +* `n == nums.length` +* 1 <= n <= 3 * 104 +* -3 * 104 <= nums[i] <= 3 * 104 \ No newline at end of file diff --git a/README.md b/README.md index c3eccf6..135c61a 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0433 |[Minimum Genetic Mutation](LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs)| Medium | String, Hash_Table, Breadth_First_Search | 1 | 78.46 | 0127 |[Word Ladder](LeetCodeNet/G0101_0200/S0127_word_ladder/Solution.cs)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 22 | 96.00 #### Day 13 Graph Theory @@ -350,6 +351,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0205 |[Isomorphic Strings](LeetCodeNet/G0201_0300/S0205_isomorphic_strings/Solution.cs)| Easy | String, Hash_Table | 2 | 90.78 +| 0392 |[Is Subsequence](LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 #### Day 3 Linked List @@ -614,6 +616,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0392 |[Is Subsequence](LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 | 0125 |[Valid Palindrome](LeetCodeNet/G0101_0200/S0125_valid_palindrome/Solution.cs)| Easy | Top_Interview_Questions, String, Two_Pointers | 1 | 99.79 | 0026 |[Remove Duplicates from Sorted Array](LeetCodeNet/G0001_0100/S0026_remove_duplicates_from_sorted_array/Solution.cs)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00 | 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) | 1 | 63.59 @@ -762,6 +765,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0125 |[Valid Palindrome](LeetCodeNet/G0101_0200/S0125_valid_palindrome/Solution.cs)| Easy | Top_Interview_Questions, String, Two_Pointers | 1 | 99.79 +| 0392 |[Is Subsequence](LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 | 0167 |[Two Sum II - Input Array Is Sorted](LeetCodeNet/G0101_0200/S0167_two_sum_ii_input_array_is_sorted/Solution.cs)| Medium | Array, Binary_Search, Two_Pointers | 0 | 100.00 | 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 @@ -806,6 +810,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | 0228 |[Summary Ranges](LeetCodeNet/G0201_0300/S0228_summary_ranges/Solution.cs)| Easy | Array | 0 | 100.00 | 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) | 6 | 39.00 | 0057 |[Insert Interval](LeetCodeNet/G0001_0100/S0057_insert_interval/Solution.cs)| Medium | Array | 1 | 99.33 +| 0452 |[Minimum Number of Arrows to Burst Balloons](LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs)| Medium | Array, Sorting, Greedy, LeetCode_75_Intervals | 51 | 49.35 #### Top Interview 150 Stack @@ -857,6 +862,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0199 |[Binary Tree Right Side View](LeetCodeNet/G0101_0200/S0199_binary_tree_right_side_view/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00 +| 0637 |[Average of Levels in Binary Tree](LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 2 | 94.69 | 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) | 0 | 100.00 | 0103 |[Binary Tree Zigzag Level Order Traversal](LeetCodeNet/G0101_0200/S0103_binary_tree_zigzag_level_order_traversal/Solution.cs)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 @@ -864,6 +870,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0530 |[Minimum Absolute Difference in BST](LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00 | 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) | 0 | 100.00 | 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)) | 0 | 100.00 @@ -874,6 +881,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) | 131 | 65.99 | 0130 |[Surrounded Regions](LeetCodeNet/G0101_0200/S0130_surrounded_regions/Solution.cs)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 1 | 100.00 | 0133 |[Clone Graph](LeetCodeNet/G0101_0200/S0133_clone_graph/Solution.cs)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 117 | 96.34 +| 0399 |[Evaluate Division](LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS | 3 | 66.56 | 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) | 4 | 91.60 | 0210 |[Course Schedule II](LeetCodeNet/G0201_0300/S0210_course_schedule_ii/Solution.cs)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 4 | 91.35 @@ -881,6 +889,8 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0909 |[Snakes and Ladders](LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/Solution.cs)| Medium | Array, Breadth_First_Search, Matrix | 6 | 72.69 +| 0433 |[Minimum Genetic Mutation](LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs)| Medium | String, Hash_Table, Breadth_First_Search | 1 | 78.46 | 0127 |[Word Ladder](LeetCodeNet/G0101_0200/S0127_word_ladder/Solution.cs)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 22 | 96.00 #### Top Interview 150 Trie @@ -909,6 +919,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0108 |[Convert Sorted Array to Binary Search Tree](LeetCodeNet/G0101_0200/S0108_convert_sorted_array_to_binary_search_tree/Solution.cs)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00 | 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)) | 37 | 40.62 +| 0427 |[Construct Quad Tree](LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs)| Medium | Array, Tree, Matrix, Divide_and_Conquer | 91 | 66.88 | 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 @@ -916,6 +927,7 @@ 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) | 1 | 100.00 +| 0918 |[Maximum Sum Circular Subarray](LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 2 | 38.75 #### Top Interview 150 Binary Search @@ -934,6 +946,7 @@ 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)) | 85 | 88.50 +| 0502 |[IPO](LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue | 199 | 62.82 | 0373 |[Find K Pairs with Smallest Sums](LeetCodeNet/G0301_0400/S0373_find_k_pairs_with_smallest_sums/Solution.cs)| Medium | Array, Heap_Priority_Queue | 52 | 73.33 | 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) | 191 | 41.28 @@ -1643,6 +1656,7 @@ 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) | 1 | 100.00 +| 0918 |[Maximum Sum Circular Subarray](LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 2 | 38.75 #### Day 6 @@ -1726,6 +1740,7 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0392 |[Is Subsequence](LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 | 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) | 14 | 69.42 | 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) | 4 | 89.69 @@ -1745,16 +1760,26 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|--------- | 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) | 14 | 69.42 +| 0918 |[Maximum Sum Circular Subarray](LeetCodeNet/G0901_1000/S0918_maximum_sum_circular_subarray/Solution.cs)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue, Dynamic_Programming_I_Day_5, Top_Interview_150_Kadane's_Algorithm | 2 | 38.75 +| 0909 |[Snakes and Ladders](LeetCodeNet/G0901_1000/S0909_snakes_and_ladders/Solution.cs)| Medium | Array, Breadth_First_Search, Matrix, Top_Interview_150_Graph_BFS | 6 | 72.69 | 0763 |[Partition Labels](LeetCodeNet/G0701_0800/S0763_partition_labels/Solution.cs)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Data_Structure_II_Day_7_String, Big_O_Time_O(n)_Space_O(1) | 2 | 86.67 | 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) | 6 | 98.90 | 0647 |[Palindromic Substrings](LeetCodeNet/G0601_0700/S0647_palindromic_substrings/Solution.cs)| Medium | String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n) | 10 | 72.48 +| 0637 |[Average of Levels in Binary Tree](LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Top_Interview_150_Binary_Tree_BFS | 2 | 94.69 | 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) | 12 | 90.27 | 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) | 0 | 100.00 +| 0530 |[Minimum Absolute Difference in BST](LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Top_Interview_150_Binary_Search_Tree | 0 | 100.00 +| 0502 |[IPO](LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue, Top_Interview_150_Heap | 199 | 62.82 | 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)) | 6 | 85.88 +| 0452 |[Minimum Number of Arrows to Burst Balloons](LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs)| Medium | Array, Sorting, Greedy, LeetCode_75_Intervals, Top_Interview_150_Intervals | 51 | 49.35 | 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) | 3 | 97.66 | 0437 |[Path Sum III](LeetCodeNet/G0401_0500/S0437_path_sum_iii/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 10 | 66.33 +| 0433 |[Minimum Genetic Mutation](LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs)| Medium | String, Hash_Table, Breadth_First_Search, Graph_Theory_I_Day_12_Breadth_First_Search, Top_Interview_150_Graph_BFS | 1 | 78.46 +| 0427 |[Construct Quad Tree](LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs)| Medium | Array, Tree, Matrix, Divide_and_Conquer, Top_Interview_150_Divide_and_Conquer | 91 | 66.88 | 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) | 22 | 82.19 +| 0399 |[Evaluate Division](LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS, Top_Interview_150_Graph_General | 3 | 66.56 | 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) | 0 | 100.00 +| 0392 |[Is Subsequence](LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers, Dynamic_Programming_I_Day_19, Level_1_Day_2_String, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers | 0 | 100.00 | 0383 |[Ransom Note](LeetCodeNet/G0301_0400/S0383_ransom_note/Solution.cs)| Easy | String, Hash_Table, Counting, Data_Structure_I_Day_6_String, Top_Interview_150_Hashmap | 1 | 98.72 | 0380 |[Insert Delete GetRandom O(1)](LeetCodeNet/G0301_0400/S0380_insert_delete_getrandom_o1/RandomizedSet.cs)| Medium | Array, Hash_Table, Math, Design, Randomized, Programming_Skills_II_Day_20, Top_Interview_150_Array/String | 10 | 100.00 | 0373 |[Find K Pairs with Smallest Sums](LeetCodeNet/G0301_0400/S0373_find_k_pairs_with_smallest_sums/Solution.cs)| Medium | Array, Heap_Priority_Queue, Top_Interview_150_Heap | 52 | 73.33 From f82115e3ead4f7872b89c5b00f33349c51f58216 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:31:53 +0300 Subject: [PATCH 2/7] Fixed compile --- LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs | 2 ++ .../S0530_minimum_absolute_difference_in_bst/Solution.cs | 1 + .../S0637_average_of_levels_in_binary_tree/Solution.cs | 1 + 3 files changed, 4 insertions(+) diff --git a/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs index 9b824a4..aabd8db 100644 --- a/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs +++ b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs @@ -3,6 +3,8 @@ namespace LeetCodeNet.G0401_0500.S0427_construct_quad_tree { // #Medium #Array #Tree #Matrix #Divide_and_Conquer #Top_Interview_150_Divide_and_Conquer // #2025_07_18_Time_91_ms_(66.88%)_Space_47.25_MB_(80.00%) +using LeetCodeNet.Com_github_leetcode; + /* // Definition for a QuadTree node. public class Node { diff --git a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs index 412f7ea..7173b76 100644 --- a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs +++ b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs @@ -4,6 +4,7 @@ namespace LeetCodeNet.G0501_0600.S0530_minimum_absolute_difference_in_bst { // #Top_Interview_150_Binary_Search_Tree #2025_07_18_Time_0_ms_(100.00%)_Space_46.02_MB_(84.51%) using System; +using LeetCodeNet.Com_github_leetcode; /** * Definition for a binary tree node. diff --git a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs index 434b440..814859b 100644 --- a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs +++ b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs @@ -5,6 +5,7 @@ namespace LeetCodeNet.G0601_0700.S0637_average_of_levels_in_binary_tree { using System; using System.Collections.Generic; +using LeetCodeNet.Com_github_leetcode; /** * Definition for a binary tree node. From 2255f6dc340de834daccf680b4185aac4e8d69b1 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:36:11 +0300 Subject: [PATCH 3/7] Fixed compile --- .../S0427_construct_quad_tree/Solution.cs | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs index aabd8db..8adf21e 100644 --- a/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs +++ b/LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs @@ -3,7 +3,57 @@ namespace LeetCodeNet.G0401_0500.S0427_construct_quad_tree { // #Medium #Array #Tree #Matrix #Divide_and_Conquer #Top_Interview_150_Divide_and_Conquer // #2025_07_18_Time_91_ms_(66.88%)_Space_47.25_MB_(80.00%) -using LeetCodeNet.Com_github_leetcode; +using System.Text; + +public class Node { + public bool val; + public bool isLeaf; + public Node? topLeft; + public Node? topRight; + public Node? bottomLeft; + public Node? bottomRight; + + public Node(bool val, bool isLeaf) { + this.val = val; + this.isLeaf = isLeaf; + this.topLeft = null; + this.topRight = null; + this.bottomLeft = null; + this.bottomRight = null; + } + + public Node( + bool val, + bool isLeaf, + Node? topLeft, + Node? topRight, + Node? bottomLeft, + Node? bottomRight) { + this.val = val; + this.isLeaf = isLeaf; + this.topLeft = topLeft; + this.topRight = topRight; + this.bottomLeft = bottomLeft; + this.bottomRight = bottomRight; + } + + public override string ToString() { + StringBuilder sb = new StringBuilder(); + sb.Append(GetNodeString(this)); + sb.Append(GetNodeString(topLeft)); + sb.Append(GetNodeString(topRight)); + sb.Append(GetNodeString(bottomLeft)); + sb.Append(GetNodeString(bottomRight)); + return sb.ToString(); + } + + private string GetNodeString(Node? node) { + if (node == null) { + return "[]"; + } + return $"[{(node.isLeaf ? "1" : "0")},{(node.val ? "1" : "0")}]"; + } +} /* // Definition for a QuadTree node. From 7855a78407f23881a69f39453d276570dfeea12c Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:41:59 +0300 Subject: [PATCH 4/7] Fixed compilation --- .../SolutionTest.cs | 21 ------ .../SolutionTest.cs | 50 -------------- .../Solution.cs | 37 ---------- .../readme.md | 28 -------- .../Solution.cs | 68 ------------------- .../readme.md | 26 ------- 6 files changed, 230 deletions(-) delete mode 100644 LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs delete mode 100644 LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs delete mode 100644 LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs delete mode 100644 LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md delete mode 100644 LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs delete mode 100644 LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md diff --git a/LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs b/LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs deleted file mode 100644 index 92b5dc4..0000000 --- a/LeetCodeNet.Tests/G0501_0600/S0530_minimum_absolute_difference_in_bst/SolutionTest.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace LeetCodeNet.G0501_0600.S0530_minimum_absolute_difference_in_bst { - -using System; -using LeetCodeNet.Com_github_leetcode; -using Xunit; - -public class SolutionTest { - [Fact] - public void GetMinimumDifference() { - TreeNode treeNode = TreeUtils.ConstructBinaryTree(new List {4, 2, 6, 1, 3}); - Assert.Equal(1, new Solution().GetMinimumDifference(treeNode)); - } - - [Fact] - public void GetMinimumDifference2() { - TreeNode treeNode = - TreeUtils.ConstructBinaryTree(new List {1, 0, 48, null, null, 12, 49}); - Assert.Equal(1, new Solution().GetMinimumDifference(treeNode)); - } -} -} diff --git a/LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs b/LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs deleted file mode 100644 index e2c8ec2..0000000 --- a/LeetCodeNet.Tests/G0601_0700/S0637_average_of_levels_in_binary_tree/SolutionTest.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace LeetCodeNet.G0601_0700.S0637_average_of_levels_in_binary_tree { - -using System; -using LeetCodeNet.Com_github_leetcode; -using Xunit; - -public class SolutionTest { - [Fact] - public void AverageOfLevels() { - TreeNode treeNode = TreeNode.Create(new List {3, 9, 20, null, null, 15, 7}); - Assert.Equal(new List {3.00000, 14.50000, 11.00000}, new Solution().AverageOfLevels(treeNode), - new DoubleListComparer(0.00001)); - } - - [Fact] public void AverageOfLevels2() { - TreeNode treeNode = TreeNode.Create(new List {3, 9, 20, 15, 7}); - Assert.Equal(new List {3.00000, 14.50000, 11.00000}, new Solution().AverageOfLevels(treeNode), - new DoubleListComparer(0.00001)); - } -} - -public class DoubleListComparer : IEqualityComparer> { - private readonly double _tolerance; - - public DoubleListComparer(double tolerance) { - _tolerance = tolerance; - } - - public bool Equals(IList x, IList y) { - if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; - if (x.Count != y.Count) return false; - - for (int i = 0; i < x.Count; i++) { - if (Math.Abs(x[i] - y[i]) > _tolerance) { - return false; - } - } - return true; - } - - public int GetHashCode(IList obj) { - int hash = 17; - foreach (var d in obj) { - hash = hash * 31 + d.GetHashCode(); - } - return hash; - } -} -} diff --git a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs deleted file mode 100644 index 7173b76..0000000 --- a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace LeetCodeNet.G0501_0600.S0530_minimum_absolute_difference_in_bst { - -// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Binary_Search_Tree -// #Top_Interview_150_Binary_Search_Tree #2025_07_18_Time_0_ms_(100.00%)_Space_46.02_MB_(84.51%) - -using System; -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 ans = int.MaxValue; - private int prev = int.MaxValue; - - public int GetMinimumDifference(TreeNode root) { - if (root == null) { - return ans; - } - GetMinimumDifference(root.left); - ans = Math.Min(ans, Math.Abs(root.val - prev)); - prev = root.val; - GetMinimumDifference(root.right); - return ans; - } -} -} diff --git a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md b/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md deleted file mode 100644 index 2a52de1..0000000 --- a/LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/readme.md +++ /dev/null @@ -1,28 +0,0 @@ -530\. Minimum Absolute Difference in BST - -Easy - -Given the `root` of a Binary Search Tree (BST), return _the minimum absolute difference between the values of any two different nodes in the tree_. - -**Example 1:** - -![](https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg) - -**Input:** root = [4,2,6,1,3] - -**Output:** 1 - -**Example 2:** - -![](https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg) - -**Input:** root = [1,0,48,null,null,12,49] - -**Output:** 1 - -**Constraints:** - -* The number of nodes in the tree is in the range [2, 104]. -* 0 <= Node.val <= 105 - -**Note:** This question is the same as 783: [https://leetcode.com/problems/minimum-distance-between-bst-nodes/](https://leetcode.com/problems/minimum-distance-between-bst-nodes/) \ No newline at end of file diff --git a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs deleted file mode 100644 index 814859b..0000000 --- a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs +++ /dev/null @@ -1,68 +0,0 @@ -namespace LeetCodeNet.G0601_0700.S0637_average_of_levels_in_binary_tree { - -// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree -// #Top_Interview_150_Binary_Tree_BFS #2025_07_18_Time_2_ms_(94.69%)_Space_51.17_MB_(31.56%) - -using System; -using System.Collections.Generic; -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 AverageOfLevels(TreeNode root) { - // Use Dictionary> to store (count, sum) for each level - // In C#, you can use a custom struct/class or Tuple for the pair. - // For simplicity, let's use double[] where [0] is count and [1] is sum. - IDictionary map = new Dictionary(); - Helper(root, map, 0); - IList result = new List(); - // Iterate through the dictionary values (which are the Double[] pairs) - // Since dictionary iteration order is not guaranteed, and we need levels in order, - // iterate up to the max level found. - int maxLevel = 0; - if (map.Count > 0) { - foreach (var key in map.Keys) { - if (key > maxLevel) { - maxLevel = key; - } - } - } - for (int i = 0; i <= maxLevel; i++) { - if (map.TryGetValue(i, out double[] pair)) { - double avg = pair[1] / pair[0]; - result.Add(avg); - } - } - return result; - } - - private void Helper(TreeNode root, IDictionary map, int level) { - if (root == null) { - return; - } - // Get or create the pair for the current level - if (!map.ContainsKey(level)) { - // Initialize count and sum - map[level] = new double[] {0.0, 0.0}; - } - // Increment count - map[level][0] += 1; - // Add value to sum - map[level][1] += root.val; - Helper(root.left, map, level + 1); - Helper(root.right, map, level + 1); - } -} -} diff --git a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md b/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md deleted file mode 100644 index 8bae0a4..0000000 --- a/LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/readme.md +++ /dev/null @@ -1,26 +0,0 @@ -637\. Average of Levels in Binary Tree - -Easy - -Given the `root` of a binary tree, return _the average value of the nodes on each level in the form of an array_. Answers within 10-5 of the actual answer will be accepted. - -**Example 1:** - -![](https://assets.leetcode.com/uploads/2021/03/09/avg1-tree.jpg) - -**Input:** root = [3,9,20,null,null,15,7] - -**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]. - -**Example 2:** - -![](https://assets.leetcode.com/uploads/2021/03/09/avg2-tree.jpg) - -**Input:** root = [3,9,20,15,7] - -**Output:** [3.00000,14.50000,11.00000] - -**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 From b0b99108eba4853c8438e939fa93f80767c70701 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:44:28 +0300 Subject: [PATCH 5/7] Fixed compile --- .../G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs b/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs index aa34078..8137787 100644 --- a/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0901_1000/S0909_snakes_and_ladders/SolutionTest.cs @@ -24,3 +24,4 @@ public void SnakesAndLadders2() { Assert.Equal(1, new Solution().SnakesAndLadders(new int[][] {new int[] {-1, -1}, new int[] {-1, 3}})); } } +} From dde43c84a0f80c61ac9a1679ae4eb7de09d26b21 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:47:59 +0300 Subject: [PATCH 6/7] Fixed compile --- .../S0399_evaluate_division/SolutionTest.cs | 61 ----------------- .../S0399_evaluate_division/Solution.cs | 66 ------------------- .../S0399_evaluate_division/readme.md | 49 -------------- 3 files changed, 176 deletions(-) delete mode 100644 LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs delete mode 100644 LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs delete mode 100644 LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md diff --git a/LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs deleted file mode 100644 index 4cb9234..0000000 --- a/LeetCodeNet.Tests/G0301_0400/S0399_evaluate_division/SolutionTest.cs +++ /dev/null @@ -1,61 +0,0 @@ -namespace LeetCodeNet.G0301_0400.S0399_evaluate_division { - -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -public static class ArrayUtils { - public static IList> GetLists(string[][] array) { - var result = new List>(); - foreach (var innerArray in array) { - result.Add(innerArray.ToList()); - } - return result; - } -} - -public class SolutionTest { - private const double Tolerance = 0.00001; - - [Fact] - public void CalcEquation() { - IList> equations = ArrayUtils.GetLists(new string[][] {new string[] {"a", "b"}, new string[] {"b", "c"}}); - double[] values = new double[] {2.0, 3.0}; - IList> queries = - ArrayUtils.GetLists( - new string[][] { - new string[] {"a", "c"}, new string[] {"b", "a"}, new string[] {"a", "e"}, new string[] {"a", "a"}, new string[] {"x", "x"} - }); - double[] expected = {6.00000, 0.50000, -1.00000, 1.00000, -1.00000}; - // For comparing double arrays with precision, use a loop or a custom assertion method - Assert.Equal(expected, new Solution().CalcEquation(equations, values, queries), Tolerance); - } - - [Fact] - public void CalcEquation2() { - IList> equations = - ArrayUtils.GetLists(new string[][] {new string[] {"a", "b"}, new string[] {"b", "c"}, new string[] {"bc", "cd"}}); - double[] values = new double[] {1.5, 2.5, 5.0}; - IList> queries = - ArrayUtils.GetLists( - new string[][] {new string[] {"a", "c"}, new string[] {"c", "b"}, new string[] {"bc", "cd"}, new string[] {"cd", "bc"}}); - double[] expected = {3.75000, 0.40000, 5.00000, 0.20000}; - Assert.Equal(expected, new Solution().CalcEquation(equations, values, queries), Tolerance); - } - - [Fact] - public void CalcEquation3() { - // Direct initialization of List> - IList> equations = new List> { - new List {"a", "b"} - }; - double[] values = new double[] {0.5}; - IList> queries = - ArrayUtils.GetLists( - new string[][] {new string[] {"a", "b"}, new string[] {"b", "a"}, new string[] {"a", "c"}, new string[] {"x", "y"}}); - double[] expected = {0.50000, 2.00000, -1.00000, -1.00000}; - Assert.Equal(expected, new Solution().CalcEquation(equations, values, queries), Tolerance); - } -} -} diff --git a/LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs b/LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs deleted file mode 100644 index 2bc8f7b..0000000 --- a/LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace LeetCodeNet.G0301_0400.S0399_evaluate_division { - -// #Medium #Array #Depth_First_Search #Breadth_First_Search #Graph #Union_Find #Shortest_Path -// #LeetCode_75_Graphs/DFS #Top_Interview_150_Graph_General -// #2025_07_18_Time_3_ms_(66.56%)_Space_48.00_MB_(43.48%) - -using System; -using System.Collections.Generic; - -public class Solution { - private Dictionary root; - private Dictionary rate; - - public double[] CalcEquation( - IList> equations, double[] values, IList> queries) { - root = new Dictionary(); - rate = new Dictionary(); - int n = equations.Count; - foreach (var equation in equations) { - string x = equation[0]; - string y = equation[1]; - root[x] = x; // In C#, Dictionary uses [] for put/get - root[y] = y; - rate[x] = 1.0; - rate[y] = 1.0; - } - for (int i = 0; i < n; ++i) { - string x = equations[i][0]; - string y = equations[i][1]; - union(x, y, values[i]); - } - double[] result = new double[queries.Count]; - for (int i = 0; i < queries.Count; ++i) { - string x = queries[i][0]; - string y = queries[i][1]; - if (!root.ContainsKey(x) || !root.ContainsKey(y)) { - result[i] = -1; - continue; - } - string rootX = findRoot(x, x, 1.0); - string rootY = findRoot(y, y, 1.0); - // In C#, string comparison uses .Equals() - result[i] = rootX.Equals(rootY) ? rate[x] / rate[y] : -1.0; - } - return result; - } - - private void union(string x, string y, double v) { - string rootX = findRoot(x, x, 1.0); - string rootY = findRoot(y, y, 1.0); - root[rootX] = rootY; - double r1 = rate[x]; - double r2 = rate[y]; - rate[rootX] = v * r2 / r1; - } - - private string findRoot(string originalX, string x, double r) { - if (root[x].Equals(x)) { // In C#, Dictionary uses [] for get - root[originalX] = x; - rate[originalX] = r * rate[x]; - return x; - } - return findRoot(originalX, root[x], r * rate[x]); - } -} -} diff --git a/LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md b/LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md deleted file mode 100644 index 18a83c5..0000000 --- a/LeetCodeNet/G0301_0400/S0399_evaluate_division/readme.md +++ /dev/null @@ -1,49 +0,0 @@ -399\. Evaluate Division - -Medium - -You are given an array of variable pairs `equations` and an array of real numbers `values`, where equations[i] = [Ai, Bi] and `values[i]` represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable. - -You are also given some `queries`, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?. - -Return _the answers to all queries_. If a single answer cannot be determined, return `-1.0`. - -**Note:** The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction. - -**Example 1:** - -**Input:** equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] - -**Output:** [6.00000,0.50000,-1.00000,1.00000,-1.00000] - -**Explanation:** - -Given: _a / b = 2.0_, _b / c = 3.0_ - -queries are: _a / c = ?_, _b / a = ?_, _a / e = ?_, _a / a = ?_, _x / x = ?_ - -return: [6.0, 0.5, -1.0, 1.0, -1.0 ] - -**Example 2:** - -**Input:** equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]] - -**Output:** [3.75000,0.40000,5.00000,0.20000] - -**Example 3:** - -**Input:** equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]] - -**Output:** [0.50000,2.00000,-1.00000,-1.00000] - -**Constraints:** - -* `1 <= equations.length <= 20` -* `equations[i].length == 2` -* 1 <= Ai.length, Bi.length <= 5 -* `values.length == equations.length` -* `0.0 < values[i] <= 20.0` -* `1 <= queries.length <= 20` -* `queries[i].length == 2` -* 1 <= Cj.length, Dj.length <= 5 -* Ai, Bi, Cj, Dj consist of lower case English letters and digits. \ No newline at end of file From bcbda50b5bfedb290e67a25172d3b85b3a7dfbc8 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 18 Jul 2025 09:51:43 +0300 Subject: [PATCH 7/7] Improved tests --- .../G0301_0400/S0392_is_subsequence/SolutionTest.cs | 4 ++-- README.md | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs b/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs index dacad31..f21d617 100644 --- a/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs +++ b/LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs @@ -6,12 +6,12 @@ namespace LeetCodeNet.G0301_0400.S0392_is_subsequence { public class SolutionTest { [Fact] public void IsSubsequence() { - Assert.Equal(true, new Solution().IsSubsequence("abc", "ahbgdc")); + Assert.True(new Solution().IsSubsequence("abc", "ahbgdc")); } [Fact] public void IsSubsequence2Test() { - Assert.Equal(false, new Solution().IsSubsequence("axc", "ahbgdc")); + Assert.False(new Solution().IsSubsequence("axc", "ahbgdc")); } } } diff --git a/README.md b/README.md index 135c61a..825a4be 100644 --- a/README.md +++ b/README.md @@ -862,7 +862,6 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0199 |[Binary Tree Right Side View](LeetCodeNet/G0101_0200/S0199_binary_tree_right_side_view/Solution.cs)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00 -| 0637 |[Average of Levels in Binary Tree](LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 2 | 94.69 | 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) | 0 | 100.00 | 0103 |[Binary Tree Zigzag Level Order Traversal](LeetCodeNet/G0101_0200/S0103_binary_tree_zigzag_level_order_traversal/Solution.cs)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 @@ -870,7 +869,6 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0530 |[Minimum Absolute Difference in BST](LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00 | 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) | 0 | 100.00 | 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)) | 0 | 100.00 @@ -881,7 +879,6 @@ 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) | 131 | 65.99 | 0130 |[Surrounded Regions](LeetCodeNet/G0101_0200/S0130_surrounded_regions/Solution.cs)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 1 | 100.00 | 0133 |[Clone Graph](LeetCodeNet/G0101_0200/S0133_clone_graph/Solution.cs)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 117 | 96.34 -| 0399 |[Evaluate Division](LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS | 3 | 66.56 | 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) | 4 | 91.60 | 0210 |[Course Schedule II](LeetCodeNet/G0201_0300/S0210_course_schedule_ii/Solution.cs)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 4 | 91.35 @@ -1765,10 +1762,8 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | 0763 |[Partition Labels](LeetCodeNet/G0701_0800/S0763_partition_labels/Solution.cs)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Data_Structure_II_Day_7_String, Big_O_Time_O(n)_Space_O(1) | 2 | 86.67 | 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) | 6 | 98.90 | 0647 |[Palindromic Substrings](LeetCodeNet/G0601_0700/S0647_palindromic_substrings/Solution.cs)| Medium | String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n) | 10 | 72.48 -| 0637 |[Average of Levels in Binary Tree](LeetCodeNet/G0601_0700/S0637_average_of_levels_in_binary_tree/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Top_Interview_150_Binary_Tree_BFS | 2 | 94.69 | 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) | 12 | 90.27 | 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) | 0 | 100.00 -| 0530 |[Minimum Absolute Difference in BST](LeetCodeNet/G0501_0600/S0530_minimum_absolute_difference_in_bst/Solution.cs)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Top_Interview_150_Binary_Search_Tree | 0 | 100.00 | 0502 |[IPO](LeetCodeNet/G0501_0600/S0502_ipo/Solution.cs)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue, Top_Interview_150_Heap | 199 | 62.82 | 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)) | 6 | 85.88 | 0452 |[Minimum Number of Arrows to Burst Balloons](LeetCodeNet/G0401_0500/S0452_minimum_number_of_arrows_to_burst_balloons/Solution.cs)| Medium | Array, Sorting, Greedy, LeetCode_75_Intervals, Top_Interview_150_Intervals | 51 | 49.35 @@ -1777,7 +1772,6 @@ C#-based LeetCode algorithm problem solutions, regularly updated. | 0433 |[Minimum Genetic Mutation](LeetCodeNet/G0401_0500/S0433_minimum_genetic_mutation/Solution.cs)| Medium | String, Hash_Table, Breadth_First_Search, Graph_Theory_I_Day_12_Breadth_First_Search, Top_Interview_150_Graph_BFS | 1 | 78.46 | 0427 |[Construct Quad Tree](LeetCodeNet/G0401_0500/S0427_construct_quad_tree/Solution.cs)| Medium | Array, Tree, Matrix, Divide_and_Conquer, Top_Interview_150_Divide_and_Conquer | 91 | 66.88 | 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) | 22 | 82.19 -| 0399 |[Evaluate Division](LeetCodeNet/G0301_0400/S0399_evaluate_division/Solution.cs)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS, Top_Interview_150_Graph_General | 3 | 66.56 | 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) | 0 | 100.00 | 0392 |[Is Subsequence](LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers, Dynamic_Programming_I_Day_19, Level_1_Day_2_String, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers | 0 | 100.00 | 0383 |[Ransom Note](LeetCodeNet/G0301_0400/S0383_ransom_note/Solution.cs)| Easy | String, Hash_Table, Counting, Data_Structure_I_Day_6_String, Top_Interview_150_Hashmap | 1 | 98.72