🎯 Day 81 of #100DaysOfCode 🎯 🔹 Problem: Reverse Only Letters – LeetCode ✨ Approach: Used a two-pointer strategy to reverse only the alphabetic characters while keeping all non-letter characters in their original positions. By moving pointers inward and swapping only when both characters are letters, the solution stays efficient and elegant! 🔄✨ 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — each character visited at most once 💾 Space Complexity: O(n) — due to character array construction ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 42.96 MB 🔑 Key Insight: Sometimes, all you need is smart pointer movement — not everything needs to be reversed, only the right pieces. #LeetCode #100DaysOfCode #DSA #TwoPointers #StringManipulation #ProblemSolving #CleanCode #AlgorithmDesign #CodingChallenge
Reversing Letters with Two Pointers in LeetCode Challenge
More Relevant Posts
-
🌟 Day 71 of #100DaysOfCode 🌟 💡 Problem: Matrix Diagonal Sum – LeetCode ✨ Approach: Traversed both primary and secondary diagonals in a single loop — adding elements smartly while avoiding double-counting the center in odd-sized matrices. Simple logic, elegant optimization! ⚡ 📊 Complexity Analysis: Time Complexity: O(n) — single traversal through the matrix rows Space Complexity: O(1) — constant auxiliary space ✅ Runtime: 0 ms (Beats 100%🔥) ✅ Memory: 46.26 MB 🔑 Key Insight: In coding, clarity wins. The shortest paths often come from the clearest logic. 🎯 #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #ProgrammingChallenge #CodeJourney #LogicBuilding #Efficiency #DeveloperGrowth #CodingDaily
To view or add a comment, sign in
-
-
💡 Day 77 of #100DaysOfCode 💡 🔹 Problem: Majority Element – LeetCode ✨ Approach: Used a sorting-based strategy to quickly identify the majority element. By sorting the array, the middle element naturally becomes the majority — simple, clean, and surprisingly powerful! 🌟 📊 Complexity Analysis: ⏱ Time Complexity: O(n log n) — due to sorting 💾 Space Complexity: O(1) — constant auxiliary space ✅ Runtime: 7 ms (Beats 39.33%) ✅ Memory: 55.75 MB 🔑 Key Insight: Sometimes the smartest solution is also the simplest — a little ordering can reveal the dominant pattern hiding in plain sight. ✨ #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #CodingDaily #ProgrammingChallenge #Sorting #LogicBuilding #CodeJourney
To view or add a comment, sign in
-
-
Cracking the "Container With Most Water" Problem in O(n)! The "Container With Most Water" (LeetCode 11) is a fantastic problem that demonstrates the power and elegance of the Two-Pointer technique. While a brute-force approach checks every pair of lines in O(n^2), the optimal solution is a O(n) algorithm. The Two-Pointer Strategy: The area of the container is defined by: Area = min(height_L, height_R) x (index_R - index_L) Maximize Width First: Start the left pointer (L) at the beginning and the right pointer (R) at the end. This guarantees the maximum possible width. Iterative Optimization: We move the pointers inward, always aiming to potentially find a taller constraining line. The Key Insight: To find a larger area, we must increase the minimum height, because the width is guaranteed to shrink. Therefore, we always move the pointer associated with the shorter line. This simple rule ensures we only check meaningful configurations, leading to a linear time complexity. #Algorithms #DataStructures #CodingInterview #TwoPointers #LinearTime #SoftwareDevelopment #100daysofcode #leetcode
To view or add a comment, sign in
-
-
🧩 LeetCode Challenge – Day 72 ✅ Dived into a string decoding problem today — a perfect blend of stacks, recursion, and pattern tracking. 🔗 LeetCode 394 – Decode String This challenge revolves around decoding expressions like 3[a2[c]], requiring careful handling of nested patterns and character reconstruction. It’s a great exercise in managing multiple layers of logic — keeping track of counts, substrings, and the overall decoded output step by step. 💡 Key Takeaways: • Stack-based parsing builds precision in handling nested structures. • Breaking problems into layers simplifies even the most complex logic. • Attention to detail is everything — one misplaced index can change the entire output. #Day72 #LeetCodeChallenge #100DaysOfCode #DSA #CodingJourney #ProblemSolving #Stack #Strings #Parsing #Recursion
To view or add a comment, sign in
-
-
⚡ Day 9 of #100 Days Of DSA Challenge Today’s focus: Remove Outermost Parentheses | Reverse Polish Notation 🔹 LeetCode 1021 – Remove Outermost Parentheses Keep a counter for open and close parentheses. Add characters to the result only when depth > 0. Avoid using a stack by tracking balance of brackets directly. Time: O(n) | Space: O(1) 🔹 LeetCode 150 – Evaluate Reverse Polish Notation (Postfix Expression) Use a stack to evaluate expressions. For each token: If number → push to stack If operator → pop two numbers, perform operation, push result back Final stack top gives the answer. Time: O(n) | Space: O(n) 💡 Key takeaway: Stack logic can often be optimized or even replaced with simple counters and pointer techniques when operations follow predictable patterns. #DSA #Stack #Queue #LeetCode #CodingChallenge #100DaysOfCode #100DaysOfDSAChallenge
To view or add a comment, sign in
-
🌟 Day 84 of #100DaysOfCode 🌟 🔹 Problem Solved: Check If All 1's Are at Least K Places Away – LeetCode Today’s challenge was all about precision, pattern detection, and distance validation within a binary array. The goal? Ensure every 1 is properly spaced and respects the minimum distance k. ✨ Approach: I iterated through the array, tracked the position of each 1, and checked the gap before encountering the next one. A simple but effective two-pointer style logic! 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — single pass through the array 💾 Space Complexity: O(1) — constant extra memory 🚀 Performance: ✔ Runtime: 1 ms (Beats 99.71%) ✔ Memory: 65.68 MB 🔑 Key Insight: Even a straightforward problem can sharpen your ability to detect patterns and handle constraints efficiently. Small details—like distances between bits—can make or break logic. #LeetCode #DSA #CodingChallenge #100DaysOfCode #ProblemSolving #BinaryArray #Algorithms #TechJourney #CodeEveryday #JavaCoding
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge Complete! Just solved "Ones and Zeroes" - a brilliant 0/1 knapsack problem with TWO constraints, showcasing optimization from 3D to 2D DP! 💡 Solution Approaches: Approach 1 - 3D Memoization (Top-Down): ✅ State: dp[index][m_remaining][n_remaining] ✅ For each string: take or skip decision ✅ Count ones and zeros for each string ✅ Memoize results to avoid recomputation ✅ Space: O(len × m × n) Approach 2 - 2D Space-Optimized (Bottom-Up): ✅ State: dp[m_used][n_used] = max strings ✅ Process each string sequentially ✅ Backward iteration prevents using same string multiple times! ✅ Space: O(m × n) ✨ The key insight: This is 0/1 knapsack with TWO constraints (m zeros, n ones). Approach 1 is intuitive with explicit take/skip decisions. Approach 2 optimizes space by processing strings one at a time and iterating BACKWARD through capacities (classic knapsack trick to ensure each item used at most once). Why backward iteration? Prevents overwriting values we still need in current iteration! Time: O(len × m × n) | Space: O(len × m × n) → O(m × n) #LeetCode #DynamicProgramming #CPlusPlus #Algorithms #SoftwareEngineering #ProblemSolving #Knapsack
To view or add a comment, sign in
-
🔢 Day 69 of #100DaysOfCode 🔢 🔹 Problem: Maximum Count of Positive and Negative Integers – LeetCode ✨ Approach: A simple yet powerful one-pass solution! Iterated through the array, counting positives and negatives separately — and returned whichever count was greater. Clean, direct, and efficient. ⚡ 📊 Complexity Analysis: Time Complexity: O(n) — single traversal of the array Space Complexity: O(1) — no extra data structures used ✅ Runtime: 1 ms (Beats 12.27%) ✅ Memory: 46.89 MB 🔑 Key Insight: Sometimes, simplicity wins — clarity in logic often outperforms complex tricks. Counting right leads to coding right! 💡 #LeetCode #100DaysOfCode #ProblemSolving #DSA #Array #AlgorithmDesign #LogicBuilding #CodeJourney #ProgrammingChallenge #CodingDaily #Efficiency
To view or add a comment, sign in
-
-
Day 22 of #100DaysOfCode Today I solved the “Permutation in String” problem on LeetCode — a tricky one that really sharpens your understanding of sliding window and frequency mapping in strings. 🧩 Problem in short: Given two strings s1 and s2, the task is to check if any permutation of s1 exists as a substring in s2. At first glance, it feels like a brute-force problem — generate all permutations of s1 and check each in s2. But that’s computational suicide for longer strings. So the challenge was to find a smarter, optimized approach. ⚙️ Intuitive Approach: Instead of generating permutations, I focused on character frequencies. Maintain two frequency arrays — one for s1 and one for the current window of s2. Slide the window across s2, adding and removing characters as you move. Whenever both frequency arrays match, it means that substring of s2 is a permutation of s1. This approach reduces the complexity drastically and relies on pattern recognition through frequency matching, not brute force. Every day in this challenge is a reminder that optimization isn’t about doing less work — it’s about doing the right work. #LeetCode #C++ #ProblemSolving #DSA #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🔗 Day 75 of #100DaysOfCode 🔗 🌳 Problem: Binary Tree Postorder Traversal – LeetCode ✨ Approach: Implemented a recursive depth-first traversal that processes the left subtree, then right subtree, and finally the root node — perfectly matching the postorder pattern (Left → Right → Root). The solution is clean, intuitive, and highlights the elegance of recursion in tree traversal! 🌿 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — each node is visited exactly once 💾 Space Complexity: O(n) — recursion stack in the worst case (skewed tree) ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 43.07 MB 💡 Key Insight: Recursion beautifully mirrors the natural hierarchy of trees — by trusting the call stack, we achieve simplicity and clarity in solving even complex traversal problems. 🌱 #LeetCode #100DaysOfCode #ProblemSolving #DSA #BinaryTree #Recursion #AlgorithmDesign #CodeJourney #ProgrammingChallenge #LogicBuilding #Efficiency #CodingDaily
To view or add a comment, sign in
-
Explore related topics
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