🚀 Day 5/30 – Understanding Stack-Based Validation Today I worked on validating balanced parentheses in a string — a classic problem that tests understanding of stacks and order of operations. The challenge was to ensure that every opening bracket has a corresponding closing bracket in the correct order. Instead of relying on pattern matching, I implemented a stack-based approach, which naturally fits this type of problem. 💡 Approach Traverse the string character by character Push opening brackets onto the stack When encountering a closing bracket, check whether it matches the most recent opening bracket If at any point the structure breaks, return false This approach ensures: O(n) time complexity O(n) space complexity (in worst case) 📊 Result ✅ Accepted (All test cases passed) ⚡ Efficient runtime performance 📚 Key Takeaway This problem reinforced an important concept: Stacks are extremely powerful when dealing with nested structures, syntax validation, and expression parsing. Small problems like this build strong fundamentals for larger system-level logic. Day 5 complete. Consistency continues. #Day5 #30DaysOfCode #LeetCode #Java #Stacks #Algorithms #DataStructures #ProblemSolving #SoftwareEngineering #CodingJourney #Consistency
Stack-Based Validation in Java
More Relevant Posts
-
𝗗𝗮𝘆 𝟯𝟲/𝟭𝟬𝟬 | 𝗠𝗲𝗿𝗴𝗲 𝗧𝘄𝗼 𝗦𝗼𝗿𝘁𝗲𝗱 𝗟𝗶𝘀𝘁𝘀 Day 36 ✅ — Recursion over iteration. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟭: Merge Two Sorted Lists (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Merge two sorted linked lists. Instead of the iterative dummy node approach, I used 𝗿𝗲𝗰𝘂𝗿𝘀𝗶𝗼𝗻. Compare the heads. Attach the smaller one, then recursively merge the rest. Base case: if one list is empty, return the other. Elegant. Three lines of logic. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Base cases: if l1 is null, return l2 (and vice versa) 👉 Compare l1.val and l2.val 👉 Attach smaller node and recurse with remaining lists Time: O(n + m), Space: O(n + m) for recursion stack 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Seven linked list problems, and recursion just made this one cleaner than iteration. Sometimes the simplest code is the most powerful. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/g4f4_B69 𝗗𝗮𝘆 𝟯𝟲/𝟭𝟬𝟬 ✅ | 𝟲𝟰 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #Recursion #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming
To view or add a comment, sign in
-
🚀 Day 11/30 – Working with Numbers Without Converting to Strings Today’s problem involved checking whether a given integer is a palindrome. While one straightforward approach would be converting the number into a string and reversing it, I chose to solve it mathematically — by reversing the digits of the number itself. 💡 Approach Immediately return false for negative numbers Store the original number Reverse the digits using modulo (% 10) and division (/ 10) Compare the reversed number with the original This avoids unnecessary string conversion and keeps the logic purely numerical. 📊 Performance ✅ All test cases passed ⚡ Efficient runtime ⏱ O(log₁₀ n) time complexity 📦 O(1) space complexity 📚 Key Takeaway Sometimes the better solution isn’t the easiest one — it’s the one that respects constraints and demonstrates deeper understanding of number manipulation. Day 11 complete. Building stronger fundamentals, one problem at a time. #Day11 #30DaysOfCode #LeetCode #Java #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
Day 7 🚀 of the #100DaysOfLeetCode challenge Problem 88: Merge Sorted Array Today’s focus was on in-place merging using the insertion and shifting approach. Instead of using an extra array, I compared elements from nums1 and nums2. Whenever an element from nums2 was smaller, I shifted the remaining elements in nums1 to the right and inserted it at the correct position. After each insertion, I updated the effective size of nums1 and continued the process until all elements were merged. This approach helped me clearly understand: -->How in-place array manipulation works -->Why boundary management (m and n) is critical -->How shifting impacts time complexity Time Complexity: O(m × n) in worst case due to shifting Space Complexity: O(1) (no extra space used) Even though there’s a more optimal two-pointer solution from the back (O(m + n)), practicing this method strengthened my fundamentals in array handling and index control. Every problem teaches something beyond just passing test cases. Consistency > Intensity. #LeetCode #Java #DataStructures #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 10/30 – Strengthening String Processing Fundamentals Today’s problem focused on determining whether two strings are anagrams of each other. Instead of sorting both strings (which would take O(n log n) time), I implemented a frequency-count approach using a fixed-size array to track character occurrences. 💡 Approach First, check if the lengths differ — if so, they cannot be anagrams. Use an integer array of size 26 (for lowercase letters). Increment counts for characters in the first string. Decrement counts for characters in the second string. If all values return to zero, the strings are valid anagrams. This approach ensures: ⏱ O(n) time complexity 📦 O(1) space complexity (constant size array) 📊 Performance ✅ All test cases passed ⚡ Efficient runtime 💾 Optimized space usage 📚 Key Takeaway Optimizing from a sorting-based solution to a frequency-count approach highlights the importance of understanding constraints. Sometimes improving complexity from O(n log n) to O(n) is not about writing more code — it's about choosing the right idea. Ten days completed. Small improvements every day compound over time. #Day10 #30DaysOfCode #LeetCode #Java #Algorithms #StringManipulation #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
⚡ Day 4 — Merge Intervals (Greedy + Sorting) Consistency is slowly turning confusion into clarity. Today’s problem was Merge Intervals — a classic example where the real difficulty isn’t coding, but recognizing the pattern. 🧩 Problem solved: Merge Intervals 🔢 LeetCode: 56 At first glance, the problem looks messy because overlapping ranges create too many comparison possibilities. The turning point was realizing that trying to merge randomly is inefficient — sorting the intervals by start time simplifies everything. Once sorted, the logic becomes straightforward: • Compare the current interval with the last merged interval • If they overlap → extend the boundary • If they don’t → push a new interval No unnecessary comparisons. Just one clean pass. 🔍 Key learnings: • Sorting often converts complex interval problems into linear scans • Greedy decisions work when local choices don’t break global correctness • Tracking only the “last merged interval” avoids redundant checks • Pattern recognition matters more than code length Slowly building the instinct to see patterns before writing loops. Solutions are available here: https://lnkd.in/gW8atfqw More tomorrow. #DSA #Java #LeetCode #GreedyAlgorithm #CodingJourney #StudentDeveloper #LearningInPublic
To view or add a comment, sign in
-
-
📌 LeetCode Daily Challenge — Day 4 Problem: 1582. Special Positions in a Binary Matrix Topic: Array, Matrix 🧠 Approach (Simple Thinking): 🔹 A position is special only if it holds a 1 that is alone in its entire row AND its entire column 🔹 Checking row and column for every cell separately is slow and repetitive 🔹 So we pre-compute rowSum and colSum in one pass before making any decisions 🔹 rowSum[i] == 1 means no other 1 exists in that row 🔹 colSum[j] == 1 means no other 1 exists in that column 🔹 If mat[i][j] == 1 and both sums equal 1 — that's your special position 🔹 Preprocessing once and reusing is the real trick here ⏱️ Time Complexity: Two passes through the full matrix → O(m × n) Every cell is visited exactly twice, nothing more 📦 Space Complexity: Two small arrays for row and column sums → O(m + n) No recursion, no extra grid, just two lightweight arrays doing all the work I wrote a full breakdown with dry run, analogy and step by step code walkthrough here: https://lnkd.in/gFgQxQRP If you approached this differently or have a cleaner way to think about it, drop it in the comments — always curious to see different perspectives 💬 See you in the next problem 👋 #LeetCode #Java #SoftwareEngineer #ProblemSolving #BackendDeveloper
To view or add a comment, sign in
-
-
🚀 Day 7/30 – Paying Attention to Edge Cases Today’s problem focused on finding the length of the last word in a given string. While it may seem straightforward, the real challenge lies in handling edge cases correctly — especially trailing spaces. Instead of splitting the string (which would use extra space), I optimized the approach by: Trimming unnecessary trailing spaces Iterating backward from the end of the string Counting characters until the next space is encountered This approach keeps the solution efficient and clean. 📊 Performance ✅ All test cases passed ⚡ 0 ms runtime (100% performance) 📉 Constant extra space 📚 Key Takeaway Sometimes, simple problems test attention to detail more than algorithmic complexity. Writing clean logic while carefully handling edge cases is just as important as solving advanced problems. Seven days in — consistency is becoming a habit. #Day7 #30DaysOfCode #LeetCode #Java #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟰𝟰/𝟭𝟬𝟬 | 𝗗𝗲𝗹𝗲𝘁𝗲 𝗡𝗼𝗱𝗲 & 𝗥𝗲𝗺𝗼𝘃𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 Day 44 ✅ — Two deletion techniques, one day. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟯𝟳: Delete Node in a Linked List (Medium) ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟬𝟯: Remove Linked List Elements (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: 𝕯𝖊𝖑𝖊𝖙𝖊 𝕹𝖔𝖉𝖊 (#237): The twist? You're only given the node to delete—not the head. Can't access previous node. Solution: Copy next node's value to current, then skip next. Clever trick that feels like breaking the rules. 𝕽𝖊𝖒𝖔𝖛𝖊 𝕰𝖑𝖊𝖒𝖊𝖓𝖙𝖘 (#203): Remove all nodes with a specific value. The standard deletion problem—handle head separately, then traverse and skip matching nodes. Two problems, two deletion strategies. Both are in-place, O(1) space. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵𝗲𝘀: 𝑫𝒆𝒍𝒆𝒕𝒆 𝑵𝒐𝒅𝒆: 👉 Copy next node's value to current 👉 Skip next node: node.next = node.next.next 𝑹𝒆𝒎𝒐𝒗𝒆 𝑬𝒍𝒆𝒎𝒆𝒏𝒕𝒔: 👉 Handle head nodes with target value first 👉 Traverse and skip nodes matching value 👉 Return potentially new head Time: O(n), Space: O(1) for both 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Fifteen linked list problems (Day 30-44). Deletion patterns are now second nature. The "Delete Node" trick shows that sometimes the clever solution isn't what you'd expect. Challenge your assumptions. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gMb9bPNy 𝗗𝗮𝘆 𝟰𝟰/𝟭𝟬𝟬 ✅ | 𝟱𝟲 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #NodeDeletion #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #InPlaceAlgorithm #Programming #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 503 of #750DaysOfCode 🔥 LeetCode 3714 — Longest Balanced Substring II (Medium) Today’s challenge was all about prefix differences, hashing, and smart optimization. We’re given a string containing only 'a', 'b', and 'c'. A substring is called balanced if all distinct characters in that substring appear the same number of times. 🧠 Key Insight Since we only have 3 characters, instead of brute-forcing every substring (which would be O(n²) ❌), we can: Track prefix counts of a, b, c Store frequency differences Use a HashMap to detect when the same difference pair appears again If two prefixes have the same difference values: (countA - countB) (countB - countC) Then the substring between them is balanced ✅ 💡 Optimization Strategy This solution smartly breaks the problem into 3 cases: 1️⃣ Only one distinct character 2️⃣ Exactly two distinct characters 3️⃣ All three characters Each case is handled efficiently using prefix differences and HashMaps. Time Complexity: O(n) Space Complexity: O(n) No brute force. No nested loops. Just pure prefix logic. 🔥 What I Learned Today ✔ Prefix difference technique is powerful ✔ Hashing states helps avoid O(n²) brute force ✔ Breaking complex problems into structured cases simplifies thinking ✔ Medium problems often test observation, not complexity “The difference between good and great coders is not syntax — it’s pattern recognition.” Onward to Day 504 💪🔥 #LeetCode #DataStructures #Algorithms #Java #CodingJourney #750DaysOfCode #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 20 of #100DaysOfCode Solved 54. Spiral Matrix on LeetCode 🌀 🧠 Key insight: Spiral traversal is all about maintaining boundaries. By shrinking the top, bottom, left, and right limits after each pass, we can cover every element exactly once. ⚙️ Approach: 🔹Maintain four pointers: top, down, left, right 🔹Traverse: 🔹Left → Right (top row) 🔹Top → Bottom (right column) 🔹Right → Left (bottom row) 🔹Bottom → Top (left column) 🔹Update boundaries after each traversal ⏱️ Time Complexity: O(m × n) 📦 Space Complexity: O(1) (excluding output list) #100DaysOfCode #LeetCode #DSA #Matrix #Java #ProblemSolving #LearningInPublic #CodingJourney
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