Day 191: Advanced Stacks and Monotonic Patterns I am on Day 191 of my coding journey. Today I focused on using Stacks to solve math problems and search for patterns in arrays. I revisited the Min Stack problem to make it faster. By storing the current minimum value along with each number in the stack, I can now find the smallest number in O(1) time. This means I do not have to look through the whole stack to find the minimum. Next, I solved the problem of removing outermost parentheses. I tried two ways to do this. First, I used a stack to track the depth. Then, I realized I could just use a simple counter variable to track the level. If the level is higher than one, I keep the bracket. This logic makes the code much smaller and faster. I also worked on Reverse Polish Notation. This is a way of writing math problems where the operators come after the numbers. A stack is the perfect tool for this. I push numbers onto the stack and whenever I see a symbol like plus or minus, I pop the top two numbers, solve them, and push the result back. Finally, I learned about the Next Greater Element. This is a very important pattern. I used a Monotonic Stack to keep track of numbers as I moved backward through the array. This allows me to find the next bigger number for every element without using a slow nested loop. Today taught me that stacks are not just for storing data. They are great for solving math and finding relationships between numbers in a list. #DSAinJavaScript #365daysOfCoding #JavaScriptLogic #LeetCode #CodingJourney #ProgrammingLogic #DataStructures #Algorithms #WebDevelopment #SoftwareEngineering #CodeNewbie #TechSkills #JavaScriptDeveloper #ProblemSolving #MonotonicStack #LogicBuilding #DailyCodingChallenge #ComputerScience #BackendDevelopment #FrontendDevelopment
Stacks for Math Problems and Patterns in Arrays
More Relevant Posts
-
🚀 Day 915 of #1000DaysOfCode ✨ Shortest Path Algorithm — Explained Mathematically We often learn shortest path algorithms from a coding perspective. But what if we step back and understand them from a mathematical point of view? In today’s post, I’ve explained the shortest path algorithm in a slightly different way — through mathematical reasoning and structure. It’s a deeper, more conceptual approach that helps you truly understand *why* the algorithm works, not just how to implement it. If you enjoy digging beneath the surface and building strong theoretical foundations behind practical coding problems, this one is for you. 👇 Do you prefer understanding algorithms conceptually first, or jumping straight into code? #Day915 #learningoftheday #1000daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #Next #CodingCommunity #Algorithms #DataStructures #SystemDesign #ProblemSolving
To view or add a comment, sign in
-
🚀 Just Published: Array Basics – Indexing & Operations | DSA Foundations Today I uploaded a new video on my YouTube channel JDCodebase where I explain one of the most important beginner topics in Data Structures — Arrays. In this video, I cover: • What is an Array • How Indexing works (and why it is O(1)) • Traversal concept • Insert at index (why it is O(n)) • Delete at index • Rotate array by 1 • Why arrays use contiguous memory I explained everything step by step in JavaScript and focused on building strong fundamentals instead of just solving problems. If you are starting DSA or want to strengthen your basics, this will help you a lot. 🎥 Video link in the comments. I’m building a complete DSA Foundations Series on JDCodebase — step by step, from zero. #DSA #DataStructures #JavaScript #Coding #Programming #LearnToCode #SoftwareDevelopment #TechLearning
To view or add a comment, sign in
-
Heaps and K-Related Problems Day 217 Today Today is day 217 of my coding challenge. I focused on using Heaps and Priority Queues to solve problems more efficiently. A very important rule I learned today is that when a question asks for the kth smallest or kth largest element, you should use a heap. The trick is to keep the heap size restricted to K. This makes the code much faster than simple sorting. I solved LeetCode 215 which is about finding the Kth largest element in an array. Instead of sorting the whole array which takes O(n log n), I used a Min-Priority Queue of size K. This reduced the time complexity to O(n log k). I also worked on LeetCode 703 where I had to find the kth largest element in a data stream. A Min-Heap is perfect here because the smallest element in a heap of size K is always the kth largest overall. For LeetCode 1046 called Last Stone Weight, the simple way uses repeated sorting which is very slow. I optimized it using a Max-Priority Queue to get a speed of O(n log n) because it always keeps the heaviest stones at the top. Another interesting problem was LeetCode 347, Top K Frequent Elements. I used a frequency map and then a Min-Priority Queue to keep only the top K frequent items. This is better than sorting because it avoids sorting elements we do not need. Finally I solved LeetCode 378 which is the Kth Smallest Element in a Sorted Matrix. Using a Min-Heap helped me find the right value efficiently by only looking at the necessary rows and columns. Using heaps is a game changer for performance especially when dealing with large amounts of data. LeetCode Questions i solved: LeetCode 215 LeetCode 703 LeetCode 1046 LeetCode 378 LeetCode 347 #DSAinJavaScript #365daysOfCoding #JavaScriptDeveloper #LeetCodeSolutions #DataStructures #AlgorithmDesign #LogicBuilding #ProblemSolving #JavaScriptProgramming #TechLearning #HeapDataStructure #PriorityQueue #CodingInterview #SoftwareEngineering #KthLargest #Optimization #CleanCode #JavaScriptLogic #CareerGrowth #ProgrammingJourney
To view or add a comment, sign in
-
LeetCode Win Today 🚀 Solved “Apply Operations to an Array” with a simple two-pass approach. ⚡ Runtime: 0 ms (Beats 100%) Approach: 🔹 Pass 1: Traverse the array If nums[j] == nums[j-1] → Double the left element → Set the right element to 0 🔹 Pass 2: Move all zeros to the end using a two-pointer technique. 💡 Key Insight: Instead of solving everything in one complex loop, split the problem into two clean steps. 📊 Complexity: • Time → O(n) • Space → O(1) (in-place) Consistent practice. Clear thinking. Better code every day. 🧠⚡ #leetcode #dsa #algorithms #datastructures #coding #programming #python #softwareengineering #computerscience #tech #codinglife #problem-solving #100daysofcode #developers #codingjourney #techcommunity 🚀
To view or add a comment, sign in
-
-
🚀 Just Published: Array Patterns – Max, Min & Frequency | DSA Foundations Today I uploaded a new video on my YouTube channel JDCodebase where I explain one of the most important thinking concepts in Data Structures — Array Patterns. In this video, I cover: • How to track Maximum and Minimum efficiently • How Frequency counting works using objects (hashmap concept) • Introduction to Prefix Sum • How to find the Second Largest element without sorting • Time & Space Complexity explanation Instead of memorizing problems, I focused on understanding patterns that can solve many questions. These concepts are used in problems like: Duplicates, Unique Elements, Majority Element, and many LeetCode questions. If you are starting DSA or want to strengthen your fundamentals, this will help you build strong logic. 🎥 Video link in the comments. I’m building a complete DSA Foundations Series on JDCodebase — step by step, from zero. #DSA #DataStructures #JavaScript #Coding #Programming #LearnToCode #SoftwareDevelopment #TechLearning #JDCodebase
To view or add a comment, sign in
-
Solving Hostel Struggles with Code: The Bill Splitter 💸💻 Day 42/100 Real-world problems require real-world logic. 🏗️ For Day 42, I decided to build something every college student needs: an Automated Expense Splitter. No more awkward math after a group dinner just clean, object-oriented logic. Technical Highlights: 📊 Cumulative Aggregation: Managing a running total of expenses across multiple class methods. 📐 Dynamic Division: Using Python’s len() function to calculate shares based on a fluctuating number of participants. 📉 Float Formatting: Implementing string formatting (:.2f) to ensure financial data is presented with professional precision. The Impact: Programming isn't just about complex algorithms; it's about making life simpler. Whether it's splitting a dinner bill or managing a corporate budget, the core logic of 'Distributed Costs' is a fundamental skill in software development. Do chech my GitHub repository here : https://lnkd.in/d9Yi9ZsC #Python #100DaysOfCode #BTech #FinTech #HostelLife #SoftwareEngineering #CleanCode #LearningInPublic #EngineeringStudent #WomenInTech
To view or add a comment, sign in
-
-
🚀 March LeetCode Challenge: Day 05/31 | The Power of Parity in the March LeetCode Challenge! One thing I love about competitive programming is finding "The Shortcut." Today, for LeetCode 1758: Minimum Changes To Make Alternating Binary String, I was able to turn a string manipulation problem into a simple mathematical observation. 🧩 The Challenge Given a binary string, what is the minimum number of character flips needed to make it "alternating" (e.g., 0101... or 1010...)? 💡 My Logic: One Loop, Two Results Initially, you might think you need to check the string against two different patterns separately. But there's a more elegant way: The Pattern Rule: In an alternating string starting with 0, the character at index i should be 0 if i is even, and 1 if i is odd. This can be represented simply as i % 2. The Complement: If it takes X operations to make the string start with 0, it will take exactly (Total Length - X) operations to make it start with 1. By calculating one, I automatically knew the other. Taking the min() of these two gave me the optimal answer in a single pass! 📊 Performance Reflection Time Complexity: O(N) – A single traversal of the string. Space Complexity: O(1) – No extra strings created, just a single counter. #LeetCode #CodingChallenge #DynamicProgramming #Cpp #SoftwareEngineering #ProblemSolving #MarchCodingChallenge #VITBhopal #DataStructures #DrGViswanathan #VIT
To view or add a comment, sign in
-
-
🔥 #19 Day of my Leetcode Streak. Consistency is slowly turning into real progress. Today I solved Problem #344 – Reverse String using C++ on LeetCode. What makes today interesting is that I also started my String topic practice, and this was the first problem I solved after understanding the theory behind strings. 📌 Quick Insight – What is a String in C++? A string is simply a sequence of characters used to represent text. In this problem, the string is given as a character array (vector<char>), and the challenge is to reverse it in-place without using extra memory. 💡 Approaches I explored while solving this: 1️⃣ Two Pointer Technique I placed one pointer at the start and another at the end of the array. By swapping the characters and gradually moving both pointers toward the center, the string gets reversed efficiently. This approach helped me understand the internal logic behind how reversal works. 2️⃣ Using the STL Inbuilt Function C++ also provides a direct and elegant solution using: reverse(s.begin(), s.end()); This single line reverses the entire container using the STL reverse algorithm. Moments like these remind me that DSA is not just about solving problems, but about understanding multiple ways to think about a solution. On to the next challenge. 🚀 #LeetCode #19DayStreak #DSAJourney #ProblemSolving #CppProgramming #CodingJourney #LearningInPublic #BuildInPublic #FutureSDE #SoftwareEngineering #DeveloperJourney #ConsistencyMatters #TechGrowth #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 End of the Week LeetCode Practice Wrapping up this week’s coding practice with another problem from the array collection on LeetCode: Remove Duplicates from Sorted Array. It’s the end of the week, and I’m glad to say I’ve already knocked down 2 problems while continuing to sharpen my problem-solving skills. 🔎 Problem Overview Given a sorted array, the task is to remove duplicates in-place so that each element appears only once. The function should return the number of unique elements (k), and the first k positions of the array should contain those unique values. The challenge is doing this without using extra space, meaning we must modify the original array efficiently. 🧠 Approach Because the array is already sorted, duplicate values appear next to each other. This makes the two-pointer technique a clean and efficient solution. • Pointer i tracks the position of the last unique element • Pointer j scans through the array • When a new unique value appears, i moves forward and we update the array This keeps the solution efficient with: • Time Complexity: O(n) • Space Complexity: O(1) ⚙️ Performance • Runtime: 4 ms (Beats 42.04%) • Memory Usage: 13.92 MB (Beats 38.66%) 💡 I’ve featured the full implementation in my LeetCode library on my LinkedIn profile, where I’m documenting my problem-solving journey. Feel free to check it out there. 📊 Week Summary ✔ Solved 2 LeetCode problems ✔ Practiced array manipulation and pointer techniques ✔ Continued building consistency in coding practice Now it's time to reset, recharge, and start getting ready for next week’s challenge. #LeetCode #Algorithms #Python #DataScienceJourney #MachineLearning #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
🚀 500 LeetCode Problems Completed — Learning the Patterns Behind DSA I recently completed 500+ problems on LeetCode, and this journey completely changed how I approach Data Structures & Algorithms. At first, DSA felt like solving endless new questions. But while practicing consistently and learning from platforms like Take U Forward (Striver’s DSA Sheet), I realized something important: 👉 DSA is not about problems — it’s about patterns. Most questions eventually map to a small number of thinking frameworks. 🔹 Recursion / Backtracking Problems mainly follow two core styles: • Exploring choices using a for-loop recursion • Take / Not Take decisions → building subsequences, subsets, and combinations 🔹 Stack Patterns Understanding monotonic stacks, next greater/smaller elements, and state management makes many “different” problems feel similar. 🔹 Sliding Window & Two Pointers Learning when to expand or shrink a window converts brute-force solutions into optimal ones. 🔹 Dynamic Programming DP becomes clearer when broken into: State → Choice → Transition → Base Case Following structured resources like Take U Forward helped transform random practice into pattern-based learning. This milestone reflects continuous learning, debugging sessions, failed submissions, and gradual improvement in problem-solving intuition. Looking forward to applying these learnings to build efficient systems and write better software 🚀 #LeetCode #TakeUForward #StriverDSASheet #DSA #ProblemSolving #CodingJourney #SoftwareEngineering
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