Intermediate·Concept·2 min read

Sliding window and two pointers in C#

Practice this question

Problems to practice

  • Longest Substring Without Repeating Characters
  • Maximum Subarray Sum of Fixed Size
  • Minimum Window Substring
  • Container With Most Water
  • Valid Palindrome

Example: two pointers palindrome

csharp
public bool IsPalindrome(string s) {
    int left = 0, right = s.Length - 1;
    while (left < right) {
        if (s[left] != s[right]) return false;
        left++;
        right--;
    }
    return true;
}

Adapted from 17_DSA_DOTNET.md · “12. Sliding window and two pointers in C#”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.