🚀 LeetCode: Valid Palindrome The goal is to determine if a string is a palindrome, considering only alphanumeric characters and ignoring cases. 🛠️ My Approach 1. Preprocessing: Converted the entire string to lowercase to ensure the check is case-insensitive. 🔡 2. Filtering: Used a regex-based loop (/[a-z0-9]/) to strip away non-alphanumeric characters, creating a clean string of only valid characters. 🧹 3. Two-Pointer Optimization: Instead of reversing the string (which takes extra time and memory), I used two pointers starting at opposite ends. 📍 One pointer moves from the start (i), and the other from the end (j). ❌ If the characters at these positions ever mismatch, we return false immediately. 📊 Efficiency Analysis ⏱️ Time Complexity: $O(n) 💾 Space Complexity: $O(n) #LeetCode #JavaScript #CodingLife #Algorithms #WebDevelopment #ProblemSolving #SoftwareEngineering #TechCommunity
LeetCode: Valid Palindrome Solution
More Relevant Posts
-
📌 #61 DailyLeetCodeDose Today's problem: 146. LRU Cache – 🟡 Medium This task looks simple until you remember the O(1) requirement. A map alone is not enough – we also need to track recency. The key idea is combining a hash map with a doubly linked list: the map gives instant access, the list keeps items ordered by usage. Every get or put moves the node to the front, making it the most recently used. When capacity is exceeded, the last node is removed – that's the true LRU. Clean design, strict O(1), and a great reminder that the right data structure is often the whole solution. https://lnkd.in/epVtDYKH #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
Balance a Binary Search Tree Using Inorder Traversal 👉 Day 87 / Day 93 👈 36 🔥 Key Points 👉 Inorder traversal guarantees sorted node values for a BST 👉 Choosing the middle element ensures height balance 👉 Recursive construction creates a balanced BST 👉 Time Complexity: O(n) 👉 Space Complexity: O(n) (for storing traversal result and recursion stack) #JavaScript #TypeScript #DataStructures #Algorithms #BinarySearchTree #Trees #DSA #CodingInterview #ProblemSolving #Recursion #LeetCode #SoftwareEngineering #FrontendDevelopers
To view or add a comment, sign in
-
-
Hash Maps = Instant Duplicate & Anagram Detection 🔎⚡ Today I solved LeetCode 217 and 242. What I learned 🧠 Both problems reduce to frequency tracking using a HashMap. - 217 Duplicate check: Store elements in a Set → if seen before, return true. - 242 Anagram check: Count frequency of characters in one string, decrement using the other. Core mental model: When comparison depends on frequency, think “counting structure”. Key takeaway 🚀 Hashing converts O(n²) comparison problems into O(n). Practical insight: If order doesn’t matter but frequency does, use Map or Set immediately. #DSA #LeetCode #Algorithms #HashMap #DataStructures #CodingInterview #JavaScript
To view or add a comment, sign in
-
From Sorted Data to Balanced Trees: Divide, Conquer, Balance 🌳 Solved LeetCode 108 - Convert Sorted Array to Binary Search Tree today. The solution clicked by treating the array like a search space: -Pick the middle element as the root -Recursively build the left half and right half -Stop when the range becomes invalid This guarantees a height-balanced BST without extra work. Key takeaway: Balanced trees are a natural outcome of divide-and-conquer. Choosing the midpoint at every step keeps depth under control. Strengthening recursive thinking and tree intuition. #LeetCode #DSA #BinarySearchTree #Recursion #DivideAndConquer #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
🚀 Cracked a tricky DSA concept today — Search in Rotated Sorted Array (with duplicates) At first glance the array looks unsorted… But actually it’s two sorted arrays joined together 🔍 Example: [2,5,6,0,0,1,2] The challenge ❓ Find a target efficiently (not O(n)) → Use Modified Binary Search (O(log n)) 💡 Key Learning: 1️⃣ One half of the array is always sorted 2️⃣ Check if target lies in the sorted half 3️⃣ If duplicates confuse the search → shrink the window (left++, right--) Core logic: • All equal → ignore edges • Left sorted → search there • Else → search right side 📈 What I learned: Understanding the logic is more important than memorizing code. Today I didn’t just solve a problem — I understood how to think like an algorithm. #DSA #BinarySearch #JavaScript #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
📌 #60 DailyLeetCodeDose Today's problem: 73. Set Matrix Zeroes – 🟡 Medium When a problem states that you must modify the data in-place, LeetCode has taught me a useful pattern: to boost performance and avoid extra memory, you can reuse the same mutable data structure to encode all the information you need. In this problem, instead of using additional arrays or hash sets, I use the first row and the first column of the matrix as markers – while scanning the matrix, whenever I encounter a zero, I mark its entire row and column by setting the corresponding cell in the first row or first column to zero. Since the first row and first column are also part of the original data, I store their initial state in two boolean flags. This allows me to correctly decide at the end whether they themselves should be zeroed out. As a result, the solution runs in O(m × n) time and uses O(1) extra space, fully satisfying the in-place requirement. https://lnkd.in/eRxwBy4g #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
📌 #45 DailyLeetCodeDose Today's problem: 141. Linked List Cycle – 🟢 Easy There are two ways to solve such tasks 1. Mark visited nodes, ex. by putting them into hash map 2. More clever way to avoid using extra space – 🦍 Floyd’s Cycle Finding Algorithm The main idea of this algorithm is to use 2 pointers at the same time: slow and fast. Slow goes by 1 step, fast by 2 on each cycle iteration. If two pointers on the same list node, we found a cycle! If you want to read more about it, here is the link: https://lnkd.in/ex25Eyvc Link to the leetcode promlem: https://lnkd.in/eM8KTdy2 #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
👉 Binary Tree Maximum Path Sum Using DFS --------------------------------------------------------------------------------------- 43 🔥 The challenge is to find the maximum sum of any path in a binary tree, where a path can start and end at any node (not necessarily passing through the root). ✔ Traverse the tree using Depth First Search (DFS) ✔ Ignore negative paths using Math.max(0, childSum) ✔ Maintain a global maximum path sum ✔ Return only one side (left or right) to the parent to maintain a valid path #DataStructures #Algorithms #BinaryTree #JavaScript #TypeScript #DSA #CodingPractice #ProblemSolving #SoftwareEngineering #FrontendDeveloper #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
📌 #57 DailyLeetCodeDose Today's problem: 221. Maximal Square – 🟡 Easy The very first, naive solution that usually comes to mind is to simply compute the size of every square encountered in the matrix. However, this approach has a major drawback: we end up traversing the same matrix elements many times. The larger the matrix is, the more noticeable and costly this problem becomes. Once we introduce memoization – storing the maximum square size that can be built starting from the current cell with given coordinates – and reuse these values, the solution immediately becomes significantly faster. In my case, the time complexity improved from O(M · N · min(M, N)) 👉 O(M · N), and the actual runtime dropped from 1561 ms 👉 11 ms So, guys, don't just make it work – make it right. https://lnkd.in/eeppiXXG #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
Day 27 of 30-day Coding Sprint 76. Minimum Window Substring - The Goal: Find the smallest substring in s that contains all characters of t (including duplicates). - The Strategy: Expand & Contract - Preprocessing: Build a frequency map (using a 256-size array) for all characters in t. - Expansion (r pointer): Move the right pointer to expand the window. If the current character is part of t and we still need more of it, increment our count. - Contraction (l pointer): Once count == m (meaning the window is "valid"), try to shrink it from the left to find the minimum possible length. - The "Squeeze": As we move l, we update our frequency map. If moving l causes us to lose a required character from t, the window becomes invalid, and we go back to expanding. Result: Efficient O(N + M) time complexity and O(256) space. #30DaysOfCode #DSASprint #LeetCode #JavaScript #SlidingWindow #HardProblem #Algorithms #Consistency
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