Skip to content

Added tasks 392-918 #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions LeetCodeNet.Tests/G0301_0400/S0392_is_subsequence/SolutionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace LeetCodeNet.G0301_0400.S0392_is_subsequence {

using System;
using Xunit;

public class SolutionTest {
[Fact]
public void IsSubsequence() {
Assert.True(new Solution().IsSubsequence("abc", "ahbgdc"));
}

[Fact]
public void IsSubsequence2Test() {
Assert.False(new Solution().IsSubsequence("axc", "ahbgdc"));
}
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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"}));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<int[]> result = new List<int[]>();
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));
}
}
}
15 changes: 15 additions & 0 deletions LeetCodeNet.Tests/G0501_0600/S0502_ipo/SolutionTest.cs
Original file line number Diff line number Diff line change
@@ -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}));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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}}));
}
}
}
Original file line number Diff line number Diff line change
@@ -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}));
}
}
}
28 changes: 28 additions & 0 deletions LeetCodeNet/G0301_0400/S0392_is_subsequence/Solution.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
27 changes: 27 additions & 0 deletions LeetCodeNet/G0301_0400/S0392_is_subsequence/readme.md
Original file line number Diff line number Diff line change
@@ -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`
* <code>0 <= t.length <= 10<sup>4</sup></code>
* `s` and `t` consist only of lowercase English letters.

**Follow up:** Suppose there are lots of incoming `s`, say <code>s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>k</sub></code> where <code>k >= 10<sup>9</sup></code>, and you want to check one by one to see if `t` has its subsequence. In this scenario, how would you change your code?
Loading
Loading