π Day 3 β Teacher's Day Challenge | Valid Palindrome Using Two Pointers


ποΈ Date: July 27, 2025
π’ Problems Solved Today: 1
π― Focus Topic: Strings, Two Pointer Technique, Character Validation
π§© Platform: Leetcode
π Table of Contents
Daily Summary
π§© Problem 1 β Valid Palindrome
π Difficulty: Easy
π§ Concepts: Two Pointers, String Cleaning, Alphanumeric Check
π Problem Statement (Summary):
Given a string s
, return true
if it is a palindrome after:
Converting to lowercase
Removing all non-alphanumeric characters
Examples:
Input:
"A man, a plan, a canal: Panama"
β Output:true
Input:
"race a car"
β Output:false
Input:
" "
β Output:true
(Empty string after cleanup is a palindrome)
π‘ Approach:
Convert all characters to lowercase
Use two pointers from start and end
Skip non-alphanumeric characters using a helper function
Compare characters and move inward
If any mismatch found, return false; else return true
π§ͺ Code (C++):
class Solution {
public:
bool isAlphaNum(char ch) {
return (ch >= 'A' && ch <= 'Z' ||
ch >= 'a' && ch <= 'z' ||
ch >= '0' && ch <= '9');
}
bool isPalindrome(string s) {
for (int i = 0; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
int st = 0, e = s.length() - 1;
while (st <= e) {
if (!isAlphaNum(s[st])) {
st++;
continue;
}
if (!isAlphaNum(s[e])) {
e--;
continue;
}
if (s[st] != s[e]) {
return false;
}
st++, e--;
}
return true;
}
};
π Time Complexity: O(n)
π¦ Space Complexity: O(1) (modifies in-place)
πΈ Submission Screenshot:
β Key Takeaways:
Lowercasing and character filtering is essential pre-processing
Two pointer pattern is efficient for palindrome check
Use helper method for clean alphanumeric validation
Donβt forget empty string edge case β itβs valid
π Daily Summary
Metric | Value |
Problems Solved | 1 |
Topics Covered | Two Pointers, Alphanumeric Filtering |
Tools Used | C++ |
Day | 3 / 30 |
π·οΈ Tags:#leetcode
#43DaysChallenge
#palindrome
#twopointers
#cpp
#strings
#validPalindrome
#dsa
Subscribe to my newsletter
Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
