Unlike Sliding Window technique, Two Pointers can starts it pointers at any index depending on the conditions given.
<aside> đź’ˇ
Two Pointers is commonly used in Sorted Array questions because the left pointer’s value is always smaller than the right pointer’s. This allows us to decide how to move the pointers based on the current value (e.g., sum) relative to the target (e.g., 2 Sum, 3 Sum) or based on duplicates (e.g., 26. Remove Duplicates, 80. Remove Duplicates from Sorted Array II).
However, this is not always the case. In Non-Sorted Array problems (e.g., 11. Container With Most Water), we move the pointers based on comparing their values rather than relying on sorting.
</aside>
https://leetcode.com/problems/valid-palindrome
Last review: Jun 11, 2025 Next review: No review needed. But you may need to revise how to make isAlphanumeric and toLower functions without using libraries.
**Anagram = Permutation** (if the word is meaningful)
**Palindrome** = **Permutation** (if the word reads the same forward and backward) ****
O(n)O(1)func isPalindrome(s string) bool {
L, R := 0, len(s)-1
for L < R {
if !isAlphanumeric(s[L]) {
L++
continue
}
if !isAlphanumeric(s[R]) {
R--
continue
}
if toLower(s[L]) != toLower(s[R]) {
return false
}
L++
R--
}
return true
}
func isAlphanumeric(c uint8) bool {
return (c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z')
}
func toLower(c uint8) uint8 {
if c >= 'A' && c <= 'Z' {
return c + 32
}
return c
}
https://leetcode.com/problems/valid-palindrome-ii/description/
Last review: Sep 15, 2025 Next review: It was good, remove from SRS.
**Anagram = Permutation** (if the word is meaningful)
**Palindrome** = **Permutation** (if the word reads the same forward and backward) ****
The description “at most” means: You are allowed to delete zero or one character — both are valid cases.
An even/odd Palindrome should be still a Palindrome after one removal. Others need to check.
O(n)