🚀 Day 58 of #100DaysOfCode Today’s problem focused on combining string processing + two pointers — 🔍 LeetCode 125: Valid Palindrome A great example of how small edge cases can make a simple problem interesting. 📌 Problem Summary Given a string s, determine whether it is a palindrome by: Ignoring non-alphanumeric characters Treating uppercase and lowercase letters as the same 🧠 Approach Used: Two Pointers ✔️ Initialize two pointers: left at the start right at the end ✔️ Skip non-alphanumeric characters ✔️ Compare characters in a case-insensitive manner ✔️ Move inward until pointers meet If all comparisons match → it’s a palindrome ✅ ⚙️ Complexity Analysis ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) ✔️ 488 / 488 test cases passed 🚀 Runtime: 2 ms (Beats ~99%) 🔥 Key Learning This problem reinforces: Two-pointer technique on strings Careful handling of edge cases Writing clean helper functions for readability Simple logic + correct filtering = solid solution 💪 Onward to Day 59 🚀 #100DaysOfCode #LeetCode #ValidPalindrome #TwoPointers #Java #DSA #ProblemSolving #CodingJourney #Consistency
Valid Palindrome Problem Solution with Two Pointers
More Relevant Posts
-
Day 2/60 – LeetCode Challenge 🔥 Problem: Valid Palindrome (LeetCode 125) Approach Used: Two Pointer Technique Intuition: Since we need to check whether a string is a palindrome (ignoring non-alphanumeric characters and case sensitivity), I used two pointers: • Start → start of string • End→ end of string Steps: 1. Move Start forward until it points to an alphanumeric character. 2. Move End backward until it points to an alphanumeric character. 3. Compare lowercase versions of both characters. 4. If mismatch → return false. 5. If match → move both pointers inward. Why this works? A palindrome reads the same from both ends. Two pointers help compare characters efficiently in one pass. Time Complexity: O(n) Space Complexity: O(1) Key Learning: When checking symmetry in strings, think two pointers before extra space. Day 2 completed ✅ On to Day 3 🚀 #LeetCode #DSA #TwoPointers #Java #CodingChallenge #PlacementPreparation
To view or add a comment, sign in
-
-
Day 3 | Problem 2 – Palindrome String Today I practised checking whether a string is a palindrome using basic two-pointer logic. Approach used: • Start comparing characters from the left and right ends • If characters match, move both pointers inward • If any mismatch occurs, the string is not a palindrome • If the loop completes, the string is a palindrome This problem helped me understand string traversal, indexing, and conditional logic more clearly. #Java #DSA #StringProblems #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 89 of #100DaysofLeetCode Problem: Minimum Size Subarray Sum Difficulty: Medium Today’s challenge was about finding the smallest length subarray whose sum is greater than or equal to a given target. Since all elements are positive, this problem is a perfect fit for the Sliding Window technique. Instead of checking all possible subarrays (which would be inefficient), I used two pointers: Expand the window by moving the right pointer and adding to the current sum. Once the sum becomes ≥ target, shrink the window from the left to find the minimum possible length. Keep updating the minimum length during this process. Key takeaways: Positive integers allow efficient window shrinking. Two pointers help reduce time complexity from O(n²) to O(n). Maintain a running sum and dynamically adjust window size. Return 0 if no valid subarray exists. Time Complexity: O(n) Space Complexity: O(1) Another solid sliding window problem completed 💪 #100DaysOfCode #100DaysOfLeetCode #LeetCode #DSA #SlidingWindow #TwoPointers #Java #ProblemSolving #CodingJourney #Algorithms
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟴/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 🎯 LeetCode 3 – Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without duplicate characters. ➤ Approach: We use the sliding window technique to dynamically track the current substring and adjust it whenever a duplicate is found. A HashMap is used to store the last seen index of each character for quick lookups. - Use two pointers (left & right) to define the current window. - Move right forward, tracking characters and their last seen index. - If a duplicate is found within the window, move left to just after the previous occurrence. - Continuously update the maximum length found. This ensures each character is processed at most twice, making the approach highly efficient. ➤ Key Insight: By using the HashMap to remember the last index of characters, we avoid re-checking parts of the string — a prime example of turning a brute-force O(n²) problem into an O(n) solution. ➤ Time Complexity: O(n) ➤ Space Complexity: O(min(n, charset size)) #LeetCode #Java #DSA #TwoPointers #ArrayManipulation #ProblemSolving #20DaysChallenge #Consistency
To view or add a comment, sign in
-
-
Day 4 – LeetCode 345 | Reverse Vowels of a String | Two Pointers Description: Continuing Day 4 of my LeetCode practice with LeetCode 345: Reverse Vowels of a String. Used the Two Pointer approach to scan from both ends, swap only vowels, and leave all other characters untouched. This avoids extra space and keeps the solution efficient. Time Complexity: O(n) Space Complexity: O(1) Key learnings: • Identifying when two pointers beat brute force • Clean character swapping logic • Handling edge cases without using unnecessary libraries Discipline beats talent. More problems coming. Tags: #LeetCode #Day4 #TwoPointers #Strings #ProblemSolving #Java #DSA #CodingJourney
To view or add a comment, sign in
-
Day 7 of Daily DSA 🚀 Solved LeetCode 238: Product of Array Except Self ✅ 🔍 Approach: Built the solution using prefix and suffix products. First pass stores left-side products in the result array Second pass multiplies them with right-side products using a single variable No division used, and handled edge cases like zeros efficiently. ⏱ Complexity: • Time: O(n) • Space: O(1) extra space (output array excluded) 📊 LeetCode Stats: • Runtime: 2 ms (Beats 94.19%) • Memory: 72.23 MB This problem is a great example of how space optimization + traversal logic can turn a seemingly tricky problem into a clean, interview-ready solution. #DSA #LeetCode #Java #Arrays #PrefixSum #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 22 of #30DaysDSAChallenge 🚀 Today’s problem: String Compression (LeetCode) 🔹 Problem Statement: Given an array of characters, compress it in-place such that consecutive repeating characters are replaced by the character followed by the count. 🔹 Approach I used: Traverse the array using two pointers. Count consecutive characters. Update the same array with: the character followed by its frequency (if > 1) Return the new length of the compressed array. 🔹 Key Learnings: How to work with in-place array modification. Efficient use of two pointers. Converting integers to characters while updating arrays. Importance of space optimization (O(1) extra space). 📈 Result: All test cases passed successfully! Consistency > Motivation. One problem every day, getting better step by step 💪 #Day22 #DSA #LeetCode #StringCompression #Java #CodingJourney #100DaysOfCode #SoftwareEngineer #ProblemSolving #MCA
To view or add a comment, sign in
-
-
#Day41 of #100DaysDSAChallenge 🚀 Today I worked on #LeetCode424 – Longest Repeating Character Replacement. The problem focuses on finding the length of the longest substring that can be converted into a string with all repeating characters by replacing at most k characters. Approaches: 1️⃣ Brute Force Check all possible substrings and validate each by counting character frequencies. Time: O(n²) Space: O(1) 2️⃣ Better Approach (Sorting / Frequency Recalculation) Maintain a sliding window but recompute maximum frequency when the window shrinks. Time: O(26 × n) ≈ O(n) Space: O(1) 3️⃣ Optimal Approach (Sliding Window + Frequency Array) Use a sliding window while tracking the maximum frequency without recomputation. Time: O(n) Space: O(1) 🔗 GitHub: https://lnkd.in/g_rSFCh8 #100DaysOfDSA #DSA #LeetCode #Java #Algorithms #DataStructures #KunalKushwaha #Striver #GeeksForGeeks #ProblemSolving #CodingJourney #LearningInPublic #InterviewPrep #PlacementPreparation
To view or add a comment, sign in
-
-
Day 17 – LeetCode 1004 | Sliding Window Done Right (O(n) Solution) Day 17 of solving problems consistently. Solved LeetCode 1004 – Max Consecutive Ones III. Problem: Given a binary array, you can flip at most k zeros. Return the maximum number of consecutive 1s possible. Brute force checks every subarray → O(n²) → wasteful. A better approach is Sliding Window + Two Pointers → O(n). Core logic: • Expand window with right pointer • Count zeros • If zeros exceed k → move left pointer • Track max window length This problem is a good reminder that: Constraints usually hint the optimal technique. If you see “subarray + max/min + linear time” → think Sliding Window first. Consistency builds skill. 17 days. No breaks. Code + explanation in the video 👇 #LeetCode #DSA #Algorithms #SlidingWindow #TwoPointers #Java #ProblemSolving #CodingInterview #SoftwareDeveloper #100DaysOfCode #TechJourney
To view or add a comment, sign in
-
Day 16 – LeetCode 1004 | Sliding Window Done Right (O(n) Solution) Day 16 of solving problems consistently. Solved LeetCode 1004 – Max Consecutive Ones III. Problem: Given a binary array, you can flip at most k zeros. Return the maximum number of consecutive 1s possible. Brute force checks every subarray → O(n²) → wasteful. A better approach is Sliding Window + Two Pointers → O(n). Core logic: • Expand window with right pointer • Count zeros • If zeros exceed k → move left pointer • Track max window length This problem is a good reminder that: Constraints usually hint the optimal technique. If you see “subarray + max/min + linear time” → think Sliding Window first. Consistency builds skill. 16 days. No breaks. Code + explanation in the video 👇 #LeetCode #DSA #Algorithms #SlidingWindow #TwoPointers #Java #ProblemSolving #CodingInterview #SoftwareDeveloper #100DaysOfCode #TechJourney
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development