🚀 Day 31 of #100DaysOfCode 💡 Problem: LeetCode 680 — Valid Palindrome II 🧠 Concepts: Two Pointers, String Manipulation Sometimes, one small allowance can make all the difference — 👉 Here, we’re allowed to delete at most one character to check if the string can still be a palindrome. So the approach was simple yet elegant: 1️⃣ Use two pointers from both ends. 2️⃣ If characters mismatch, try skipping either the left or the right one — check both possibilities. 3️⃣ If any path forms a palindrome, return true ✅ This problem beautifully shows how a small constraint tweak (like “delete at most one char”) transforms logic from basic palindrome check → into a clever conditional validation. 🔥 Lesson: Sometimes in life (and code), you don’t have to be perfect — just one small correction can still make things right. #LeetCode #Java #TwoPointers #ProblemSolving #DSA #CodingJourney #100DaysOfCode #LearnEveryday
Solved LeetCode 680: Valid Palindrome II with Two Pointers
More Relevant Posts
-
Today’s problem: Palindrome Number 🔢 Problem: Check whether a given integer is a palindrome (reads the same forward and backward). Examples: 121 → true ✅ -121 → false ❌ 10 → false ❌ Approach I used: ✅ Negative numbers are not palindromes. ✅ Convert the integer to a string. ✅ Use two-pointer technique (left and right) to compare characters from both ends. ✅ If all pairs match → it’s a palindrome. A clean and efficient way to solve this classic problem. ⚡
To view or add a comment, sign in
-
-
🔐 Day 13 of #Blind75 Challenge 🎯 Problem: Longest Substring Without Repeating Characters 🧩 Platform: LeetCode (#3) 💡 Category: Sliding Window / HashMap 🧠 Problem Statement Given a string s, find the length of the longest substring without repeating characters. Example: Input: s = "abcabcbb" Output: 3 // "abc" 💻 Approach Brute force would check all substrings — O(n²) 🚫 Instead, we use a sliding window with a HashMap to track characters efficiently: 1️⃣ Use two pointers left and right to represent the window. 2️⃣ Expand right to include new characters. 3️⃣ If a duplicate is found, move left past the previous occurrence. 4️⃣ Keep updating the max window size. ⚙️ Complexity ⏱ Time: O(n) 💾 Space: O(min(n, charset)) ✨ Takeaway A beautiful demonstration of the Sliding Window technique — dynamically adjusting boundaries instead of reprocessing everything. This problem teaches how to think in windows, not loops 🔄 #Blind75 #LeetCode #Java #DSA #CodingChallenge #ProblemSolving #SlidingWindow #DailyCoding #CareerGrowth
To view or add a comment, sign in
-
-
NeetCode 20 | LeetCode #567 | Permutation in String Applied sliding window with character frequency tracking to efficiently check for permutations in a string. A great exercise in combining logic, hash maps, and window optimization. #NeetCode #LeetCode #Java #DSA #Algorithms #SlidingWindow #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
✨ Day 55 of 100: Remove Nth Node From End of List ✨ Today’s challenge was LeetCode 19 – Remove Nth Node From End of List 💫 🧩 The task: Given the head of a linked list, remove the n-th node from the end and return the head of the modified list. 💡 Key Takeaways: 🔹 Strengthened understanding of the two-pointer technique (fast & slow pointers). 🔹 Learned how to efficiently find the target node in one pass, avoiding the need to calculate the length first. 🔹 Practiced handling edge cases, such as removing the head node. 🚀 Concept reinforced: Efficient linked list traversal using two-pointer approach — a powerful pattern for many linked list problems. #100DaysOfCode #Day55 #LeetCode #Java #LinkedList #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 72 of #LeetCode100DaysChallenge Solved LeetCode 9: Palindrome Number — a simple but foundational problem that strengthens number manipulation and logic-building skills. 🧩 Problem: Given an integer x, return true if it is a palindrome, and false otherwise. A palindrome reads the same forward and backward. No string conversion should ideally be used for an optimal solution. 💡 Approach — Reverse Half the Number: 1️⃣ Negative numbers are not palindromes. 2️⃣ Numbers ending in 0 (except 0 itself) cannot be palindromes. 3️⃣ Reverse half of the digits and compare with the remaining half. 4️⃣ If both halves match, it's a palindrome. ⚙️ Complexity: Time: O(log₁₀ N) — reversing digits Space: O(1) — constant space ✨ Key Takeaways: ✅ Improved understanding of integer operations and digit reversal. ✅ Learned how to avoid string-based approaches for cleaner, faster logic. ✅ Strengthened mathematical reasoning for number-based problems. #LeetCode #100DaysOfCode #Java #Math #Palindrome #DSA #ProblemSolving #CodingJourney #WomenInTech
To view or add a comment, sign in
-
-
📌 Day 18/100 - Valid Palindrome (LeetCode 125) 🔹 Problem: Determine whether a string reads the same forward and backward, ignoring case and non-alphanumeric characters. 🔹 Approach: Implemented a two-pointer technique. Skipped all non-alphanumeric characters. Compared characters from both ends in lowercase. Returned true if all matched, otherwise false. 🔹 Key Learning: Two-pointer method keeps logic clean and efficient. Character handling is key when data isn’t uniform. Time complexity: O(n), Space complexity: O(1). Sometimes, solving elegantly is better than solving fast. ✨ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
📌 Day 12/100 – 100 Days of Code Challenge 🚀 Today’s LeetCode challenge: “Trapping Rain Water” (LeetCode #42) – one of the most popular Hard-level problems that strengthens logic building and array manipulation skills. 🔹 Approach: Used precomputed leftMax and rightMax arrays to determine how much water each bar can trap. For every index, the trapped water = min(leftMax[i], rightMax[i]) - height[i]. 🔹 Key Learnings: Improved understanding of prefix and suffix computations. Reinforced problem-solving using array-based preprocessing. Time Complexity: O(n) Space Complexity: O(n) #100DaysOfCode #LeetCode #Java #DSA #Arrays #TwoPointer #ProblemSolving #CodingJourney #DynamicProgramming #DailyChallenge
To view or add a comment, sign in
-
-
DSA Practice – Day 71 🚀 Problem: Palindrome Partitioning (LeetCode 131) ✨ Optimal Approach — Backtracking + On-the-fly Palindrome Check We generate all valid partitions, but we optimize by: 1. Expanding the string from the current index. 2. Every time we find a palindrome substring: Add it to the current path. Recurse for the remaining string. 3. Remove last added substring (backtrack). 4. Continue exploring further partitions. ➡️ We only proceed when the substring is a palindrome — saving huge computation. Time Complexity: O(2ⁿ · n) Space Complexity: O(n) (path + recursion stack) 🌟 Key Idea Break the string at every position where the left substring is a palindrome. Then repeat the same for the right part. Using backtracking, we explore all valid partitions efficiently without recomputing paths. #Day71 #Backtracking #String #DSA #Java #LeetCode #Placements
To view or add a comment, sign in
-
-
Day 41 of #100DaysOfCode 💻🔥🚀 Problem: 2090. K Radius Subarray Averages 📊 💡 My Intuition: For each index, we need to calculate the average of the subarray centered at that index with radius k. If the total window size 2*k + 1 exceeds the array length, the average doesn’t exist — so we mark it as -1. To make this efficient, I used a Sliding Window 🪟 — maintaining a running sum instead of recalculating everything again and again. Simple, clean, and fast ⚡ 🧠 Approach: Use two pointers i and j ➡️ to maintain a window of size 2*k + 1. Keep track of the sum using long (to handle big numbers 💪). Once the window size matches, compute the average 🎯 and slide ahead ➡️. ⚙️ Time Complexity: O(n) 💾 Space Complexity: O(n) ✅ Efficient ✅ Handles edge cases (k = 0, large k, etc.) 🚀 Key Takeaway: Even problems that look complicated often crumble when you use the right pattern — Sliding Window keeps things elegant and efficient 💯 #Java ☕ #DSA #LeetCode #ProblemSolving #CodingJourney #100DaysOfCodeChallenge #CodeEveryday
To view or add a comment, sign in
-
-
DSA Practice – Day 61 🚀 Problem: Check if a Linked List is Palindrome (LeetCode 234) ⚡Brute Force (Using Stack) 1.Traverse the linked list and push all node values into a Stack. 2.Traverse the list again and compare each value with the top of the stack. 3.If all values match then, Palindrome Time Complexity: O(n) Space Complexity: O(n) ⚡ Optimal Approach (Two-Pointer + Reverse Second Half) 1. Use slow & fast pointers to find the middle. 2. Reverse the second half of the list. 3. Compare first half & reversed second half. 4. If same then ,Palindrome Time Complexity: O(n) Space Complexity: O(1) ✅ What I Learned: Stack helps in reversing order easily. Slow-fast pointer technique is very useful in linked list problems. Reversing only half the list reduces space complexity. #LinkedList #Palindrome #Stack #TwoPointers #Java #DSA #CodingJourney #PlacementPrep #LeetCode
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
Nice solution