Last week, I solved several coding problems using Stacks. At first, it felt like just another data structure. But something interesting happened. The more problems I solved, the more I realized how many real problems actually use stacks behind the scenes. For example: • Valid Parentheses • Remove Adjacent Duplicates • Remove Outer Parentheses • Decode String like 3[a2[c]] • Longest Valid Parentheses • Simplifying a File Path At first glance, these problems look completely different. But once you see the pattern, the solution becomes clearer: 👉 Push when something opens 👉 Pop when something closes 👉 Use the last element to validate or build the result That’s the beauty of problem solving in programming. Different problems. Different stories. But sometimes the same simple idea solves them all. This week reminded me of an important lesson: Mastering fundamentals like Stacks, Queues, and HashMaps makes complex problems much easier. Because good developers don’t just memorize solutions, They recognize patterns. #DataStructures #Algorithms #Java #CodingJourney #ProblemSolving #Developers
Mastering Stacks Solves Complex Problems
More Relevant Posts
-
100 Days of Code Day-21 🔗 Merging Two Sorted Linked Lists – LeetCode Problem Today, I worked on a classic problem of merging two sorted linked lists into one sorted list. 💡 The approach is simple: Compare elements from both lists Attach the smaller node to the result Continue until all nodes are merged 📌 This problem helped me strengthen my understanding of: • Linked Lists • Two-pointer technique • Efficient problem-solving 🚀 Time Complexity: O(n + m) 🚀 Space Complexity: O(1) Consistency is key in mastering Data Structures & Algorithms! #leetcode #datastructures #java #coding #problemSolving #learning #developers
To view or add a comment, sign in
-
-
🚀 Day 8 of 30 Days Coding Challenge Today I solved a problem on LeetCode: Minimum Distance Between Three Equal Elements. 🔍 Approach: Initially implemented a brute-force solution using three nested loops (O(n³)). It worked for smaller constraints but highlighted the importance of optimizing. 💡 Key Learning: Instead of checking all possible triplets, grouping indices of identical elements and analyzing consecutive occurrences leads to a much more efficient solution. ⚡ Optimization Insight: Reduced time complexity from O(n³) → O(n) Leveraged HashMap to store indices and process only relevant combinations. 📈 Takeaway: This problem reinforced an important concept: 👉 When dealing with repeated elements, think in terms of grouping and patterns rather than brute force. Consistency is key — learning something new every day and improving step by step. #Day8 #30DaysOfCode #CodingChallenge #LeetCode #Java #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnToCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 49 of My Coding Journey Today I solved an interesting problem: Row with Maximum 1s in a Binary Matrix 🧠 Problem Insight: Given a 2D binary matrix where each row is sorted (0s first, then 1s), the goal is to find the index of the first row that contains the maximum number of 1s. ⚡ My Approach: At first, I thought of a brute force solution by counting 1s in every row. It works, but it's not efficient. Then I realized an important property: 👉 Since each row is sorted, once we find the first 1, all elements to the right are also 1. So instead of checking every element: Start from the top-right corner Move left if you find 1 Move down if you find 0 This reduces the time complexity to O(n + m) 🚀 💡 Key Learning: Understanding the structure of the data (sorted rows) can help optimize the solution drastically. 📌 Result: Successfully found the row index with maximum 1s efficiently. Every day, I’m getting better at recognizing patterns and optimizing solutions 💪 #Day49 #CodingJourney #Java #ProblemSolving #DataStructures #Algorithms #Learning #Consistency My way ===== // User function Template for Java class Solution { public int rowWithMax1s(int arr[][]) { int c=0,l=0,a=0; for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[i].length;j++) { if(arr[i][j]==1) { c++; } } if(c>l) { l=c; a=i; } c=0; } if(l>0) { return a; } else { return -1; } } }
To view or add a comment, sign in
-
-
🚀 Solved “Search Insert Position” using Binary Search on LeetCode! Today I worked on an interesting problem where the goal is to find the index of a target element in a sorted array. If the target is not present, we return the index where it should be inserted to maintain sorted order. 🔍 Approach: Instead of using a linear search (O(n)), I implemented an efficient Binary Search (O(log n)) approach. 💡 Key Learning: One important detail is calculating the middle index safely: mid = low + (high - low) / 2 This avoids potential integer overflow compared to (low + high) / 2 and ensures correct behavior even for large inputs. ⚙️ Logic: If target == arr[mid] → return mid If target > arr[mid] → search right half Else → search left half If not found → return ‘low’ as the correct insert position 📈 Result: Achieved 100% performance on LeetCode 🚀 This problem reinforced my understanding of: ✔ Binary Search fundamentals ✔ Edge case handling ✔ Writing optimized and safe code Looking forward to solving more problems and improving problem-solving skills! #LeetCode #BinarySearch #Java #DataStructures #Coding #ProblemSolving
To view or add a comment, sign in
-
-
Day 44- Ever wondered how one class can use another class without inheriting it? That’s exactly what the Has-A relationship is all about. Instead of making one class do everything, we let classes work together. 🔹 What is Has-A relationship? Has-A means: One class contains another class as a part of it. It doesn’t inherit behavior, it simply uses another object to perform tasks. This helps in building clean and modular code. 🔹 Let’s understand with a simple example class Test { void play() { System.out.println("Executing play()......"); } } class Example { Test ref; Example(Test ref) { this.ref = ref; } } public class MainClass2 { public static void main(String[] args) { Test t1 = new Test(); Example e1 = new Example(t1); e1.ref.play(); } } 🔹 What’s happening here? • A Test object is created • That object is passed into Example • Example stores it using a reference (ref) • Then Example uses it to call play() 🔹 Why this is Has-A? Because: 👉 Example HAS-A Test object 👉 It is not extending Test 👉 It is simply using Test’s functionality 🔹 Type of relationship here This is Aggregation (Weak Has-A) ✔ The Test object exists independently ✔ It is created outside and passed into Example ✔ Both classes are loosely connected 🔹 Why this matters Using Has-A relationship helps in: • Better code structure • Reusability of classes • Loose coupling • Real-world modelling Instead of writing one big class, we design systems where objects collaborate. #Java #OOP #ObjectOrientedProgramming #JavaProgramming #Coding #Programming #SoftwareDevelopment #Developer #LearningInPublic #TechLearning #ComputerScience #CodingJourney #CodeNewbie #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 42 of My LeetCode Journey Today’s problem: Regular Expression Matching This wasn’t just another coding problem — it forced me to think in terms of state transitions and decision trees, not brute force. 🔍 Key Learning: - Pure recursion is not enough → leads to exponential time - Introduced Dynamic Programming (Top-Down with Memoization) - Learned how to break the problem into: - Matching current characters - Handling "*" (zero or more occurrences) 🧠 Core Insight: Instead of trying all possibilities blindly, cache results of subproblems → avoids recomputation. ⚡ Result: - Runtime: 1 ms (Beats 99.99%) - Efficient DP solution with optimal pruning 💡 Takeaway: Hard problems aren’t about syntax — they’re about modeling the problem correctly. #Day42 #LeetCode #DataStructures #DynamicProgramming #Java #CodingJourney
To view or add a comment, sign in
-
-
I solved my 156th LeetCode problem last week. Problem 1 took me 40 minutes. I gave up. Googled the answer. Felt terrible. Problem 156 — I spotted the pattern What changed? Not intelligence. Not talent. Pattern recognition. Here is what 156 problems taught me: → Most problems are just combinations of 5 patterns → Two Pointers → Sliding Window → HashMap for fast lookups → Recursion with base cases → Sorting then searching Once you see the pattern, the problem becomes familiar. Even if you have never seen it before. The biggest mistake I made early on: I was solving problems randomly. Arrays today. Trees tomorrow. Graphs next day. No structure. No depth. Just random practice. Progress was slow and frustrating. The shift happened when I stopped solving randomly and started mastering one pattern at a time. 20 to 30 problems per pattern. Suddenly, problems that looked impossible became recognizable. The truth about LeetCode nobody tells you: It does not test intelligence. It tests pattern memory and calm thinking under pressure. Both are trainable. I am still learning. Still improving every day. But 156 problems taught me one thing clearly Consistency beats talent every single time. What is your current LeetCode count? Drop it below — no judgment! 👇 #DSA #LeetCode #BackendDevelopment #Java #JavaDeveloper #BuildInPublic #CareerTransition
To view or add a comment, sign in
-
🚀 Day 2 of #100DaysOfCode — Majority Element (LeetCode 169) Today I solved the Majority Element problem using the Boyer-Moore Voting Algorithm — a brilliant technique that finds the majority element in O(n) time and O(1) space. 💡 Key Takeaways: • Learned how cancelling non-majority elements still preserves the majority • Understood why Boyer-Moore is more optimal than sorting or HashMap • Practiced writing clean and efficient Java code Problem: Find the element that appears more than ⌊n/2⌋ times in an array. Every day, one step closer to mastering Data Structures & Algorithms and becoming a better Software Engineer. 🔥 Consistency > Perfection. #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #SoftwareEngineering #LearningInPublic #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 56 of my DSA Journey Today, I worked on a Hard-level problem from LeetCode: 👉 Problem #4 – Median of Two Sorted Arrays (LeetCode) This problem is well-known for its complexity and is frequently asked in top product-based companies. 💡 What I focused on: Understanding the problem deeply instead of jumping directly to the optimal solution Implementing a merge + sort approach to build a clear foundation Applying the two-pointer technique to efficiently identify the median Handling both odd and even length cases carefully ⚙️ Approach Used: Merged both input arrays into a single array Sorted the combined array Used two pointers (i and j) moving towards the center Determined the median based on whether the length is odd or even 📈 Key Learning: Even though the optimal solution has a time complexity of O(log(min(m, n))), building a correct and intuitive approach first is crucial. It strengthens problem-solving skills and helps in understanding advanced techniques later. 🎯 Takeaway: Consistency and clarity in logic are more important than immediately writing the most optimized code. 🔥 Step by step, moving closer to mastering Data Structures & Algorithms. #DSA #LeetCode #ProblemSolving #Java #CodingJourney #PlacementPreparation #Consistency #Learning
To view or add a comment, sign in
-
-
Day 17 / 90 — Software Engineering Challenge Today I focused on revising Object-Oriented Programming (OOP) in Python to write more structured and maintainable code. Concepts Revised • Classes and Objects • Encapsulation and Abstraction • Inheritance and Polymorphism • Constructors and method definitions • Instance vs class variables • Writing modular and reusable code • Organizing logic using classes instead of functions • Improving code readability and maintainability Practical Thinking: Understanding how OOP helps in backend development: • Models → represent data (e.g., User, Task) • Services → handle business logic • Better separation of concerns Well-structured code is easier to debug, extend, and maintain. #90DaysOfCode #Python #OOP #SoftwareEngineering #LearningInPublic
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