🚀 Day 66 of #100DaysOfCode Today’s problem was LeetCode 155 — Min Stack 🧠💪 📌 Problem Summary: We need to design a stack that supports: push() pop() top() getMin() (returns minimum element in O(1) time) All operations must be O(1) — that’s the tricky part. ⚡ 📌 Approach: 👉 Use a single stack to store modified values 👉 Track the minimum separately using a variable 👉 When pushing a smaller value, encode it cleverly so you can retrieve the previous min during pop() 💡 Key Insight: When inserting a value smaller than the current minimum: st.push(2*x - min) min = x This way, the stack encodes both data and min info efficiently. 📌 Complexity: ⏱ Time: O(1) for all operations 💾 Space: O(n) ✨ Learning: This is a great example of space optimization and bit manipulation logic — classic low-level trick that feels like magic the first time you see it! ⚙️ Raj Vikramaditya Raghav Garg Nancy Solanki Shweta Arora Harsh Raj Harshita Verma Love Babbar Prince Singh Shivam Mahajan Rohit Negi Neeraj Walia Nishant Chahar Kushal Vijay #LeetCode #100DaysOfCode #CodingChallenge #Cplusplus #DataStructures #LinkedList #ProblemSolving #SoftwareEngineering #Developers #Programming #TechJourney #KeepLearning #DailyCoding #CodeNewbie#LeetCode #100DaysOfCode #Programming #Cplusplus #LinkedList #ProblemSolving #SoftwareEngineering #TechJourney #CodeNewbie #DSA
Solved LeetCode 155 Min Stack with clever encoding
More Relevant Posts
-
🚀 Day 63 of #100DaysOfCode Today I tackled LeetCode 84 — Largest Rectangle in Histogram using C++ 💪 📌 Problem Summary: Given an array representing the heights of bars in a histogram, the goal is to find the largest rectangular area that can be formed within the histogram. For example: Input: [2,1,5,6,2,3] Output: 10 (formed between heights 5 and 6) 📌 Approach: This is a classic stack-based problem involving Next Smaller Element (NSE) and Previous Smaller Element (PSE) logic. Steps: 1️⃣ Use a monotonic stack to find the index of the next smaller element for each bar. 2️⃣ Similarly, find the previous smaller element for each bar. 3️⃣ Compute width = nsi[i] - psi[i] - 1 4️⃣ Calculate area = height[i] * width and keep track of the maximum. 📌 Complexity: ⏱ Time: O(n) — each element is pushed and popped once. 💾 Space: O(n) — for storing stack and helper arrays. 📌 Key Learning: This problem strengthens the understanding of monotonic stacks, boundary calculations, and range-based area determination — a foundation for many advanced DSA problems (like Maximal Rectangle). Consistency pays off — 60 days strong and still coding daily! 🔥 Raj Vikramaditya Raghav Garg Nancy Solanki Shweta Arora Harsh Raj Harshita Verma Love Babbar Prince Singh Shivam Mahajan Rohit Negi Neeraj Walia Nishant Chahar Kushal Vijay #LeetCode #100DaysOfCode #CodingChallenge #Cplusplus #DataStructures #LinkedList #ProblemSolving #SoftwareEngineering #Developers #Programming #TechJourney #KeepLearning #DailyCoding #CodeNewbie#LeetCode #100DaysOfCode #Programming #Cplusplus #LinkedList #ProblemSolving #SoftwareEngineering #TechJourney #CodeNewbie #DSA
To view or add a comment, sign in
-
-
🚀 Day 63 of #100DaysOfCode Today I solved a C++ problem: 👉 Find K Pairs with Smallest Sums 🧩 Problem Summary: Given two sorted arrays arr1 and arr2, and an integer k, the task is to find k pairs (a, b) where a belongs to arr1 and b belongs to arr2, such that their sum is among the smallest possible. 🧠 Approach: I used a min-heap (priority_queue with greater comparator) to always extract the smallest pair sum efficiently. Start by pushing the smallest possible pairs from arr1 and the first element of arr2. Each time we pop the smallest pair, we add the next possible pair from the same row. Continue until we find k pairs. ⚙️ Key Concepts: Priority Queue (Min-Heap) Pair Sum Optimization Efficient use of STL 💡 Complexity: Time: O(k log k) Space: O(k) 👨💻 Language: C++ (STL-based) #100DaysOfCode #Day63 #CPlusPlus #STL #CodingChallenge #DSA #ProblemSolving #LeetCode #CodeNewbie #Programmer #LearnCoding #CompetitiveProgramming #cpp #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🟩 Day 56 of Leetcode 150 days challenge – Add Two Numbers (LeetCode #2) #LeetCode150 #Day56 #AddTwoNumbers #LinkedList #DataStructures #Algorithms #ProblemSolving #LeetCode #CodingChallenge #CPP #Programming #150DaysOfCode #LearnDSA #SDEPrep #CodingJourney 🔹 Problem: Given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each node contains a single digit. Add the two numbers and return the sum as a linked list. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807 🧠 Approach: We perform the addition just like we do on paper: Initialize a carry as 0. Traverse both lists simultaneously. Add the digits from both lists + carry. Store the last digit in a new node. Update carry = sum / 10. Continue until both lists are done and carry is 0. 🕒 Time Complexity: O(max(M, N)) 💾 Space Complexity: O(max(M, N)) 🏁 Key Takeaway: Linked list addition is a classic problem that strengthens your understanding of pointer manipulation, carry handling, and edge cases like unequal list lengths. 💡
To view or add a comment, sign in
-
-
🥷 Day 164 of My 365 LeetCode Challenge is done! 💥 Kicked off strong, solved my problem, and the coding vibe is awesome! 🧠 💡 LeetCode 1625 — Lexicographically Smallest String After Applying Operations Today’s challenge was an interesting blend of string manipulation, BFS traversal, and modular arithmetic — the kind of problem that truly sharpens both your algorithmic thinking and pattern recognition skills. 🧠✨ We’re given a numeric string s and two integers a and b. Two operations can be performed repeatedly in any order: 1️⃣ Add a to all digits at odd indices (with digits wrapping around modulo 10). 2️⃣ Rotate the string to the right by b positions. The goal? 🔍 Find the lexicographically smallest string possible after performing any number of these operations. Sounds simple, right? But here’s the catch — since operations can be performed infinitely, the problem hides a state-space exploration challenge. The same string can appear multiple times via different paths, so blindly iterating could easily lead to infinite loops or redundant computations. ⚙️ Approach & Thought Process: To systematically explore all possible transformations, I used Breadth-First Search (BFS) — perfect for enumerating all reachable states in minimal steps. 🔸 Step 1: Start from the original string and push it into a queue. 🔸 Step 2: For each string, perform both allowed operations: - Add a to digits at odd indices (handling digit wraparound using (digit + a) % 10). - Rotate the string by b positions. 🔸 Step 3: Use a set to track all previously visited strings to prevent cycles. 🔸 Step 4: Continuously compare and update the smallest lexicographic string seen so far. Once the queue is exhausted, the smallest recorded string is our answer ✅ 🔥 Key Learning: This problem elegantly demonstrates how graph traversal (BFS) can be applied beyond traditional graphs — even on state transformations of strings. Recognizing this pattern is a huge step toward mastering advanced algorithmic thinking. ✨ Every problem like this one is a reminder that great coding isn’t about memorizing — it’s about seeing structure where others see chaos. #LeetCode #CPlusPlus #CodingChallenge #ProblemSolving #Algorithms #BFS #SoftwareEngineering #Programming #LearningJourney #CodeNewbie #DataStructures
To view or add a comment, sign in
-
-
📌 Day 155 of Coding - Next Greater Numerically Balanced Number (LeetCode - Medium) 🎯 Goal: Find the smallest integer greater than n such that the count of each digit d in the number is exactly d (for digits 1-7). 💡Approach & Debugging: Used backtracking to generate all “beautiful” numbers following the digit count rule. A helper function generate() recursively built numbers by trying digits 1-7, ensuring that no digit appeared more times than its own value. Checked each generated number using isBeautiful(). After generation, sorted the list and returned the first number greater than n. ✔️ Time Complexity: Exponential (backtracking-based generation, but limited by small constraints). ✔️ Space Complexity: O(1) auxiliary + O(M) list for generated numbers. 🧠 Key Takeaways: Precomputation and pruning (like limiting to 1224444) help keep recursion efficient. Problems mixing digit frequency logic and recursion sharpen number theory intuition. #Day155 #LeetCode #Backtracking #Recursion #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🎯 Day 10 of my 120 Days of Coding Challenge — LeetCode Problem 10: Regular Expression Matching (Hard) Today’s challenge was one of the classic Dynamic Programming problems that really tests your logical thinking and pattern-handling skills! 💡 🧩 Problem Statement: Given a string s and a pattern p, we need to determine if the entire string matches the pattern. The pattern may contain: . → Matches any single character * → Matches zero or more of the preceding element For example: s = "aa", p = "a" → ❌ (no match) s = "aa", p = "a*" → ✅ (matches) s = "ab", p = ".*" → ✅ (matches any string) 💭 Approach Used: I used a Dynamic Programming (DP) approach to efficiently check matches between prefixes of s and p. Here’s how I broke it down: Define dp[i][j] as whether the first i characters of s match the first j characters of p. Handle base cases like empty strings and patterns with *. Build up the DP table based on matching rules: Direct match or . → inherit from dp[i-1][j-1]. * → can represent zero or multiple occurrences of the previous character. ⏱ Time Complexity: O(m × n) 📦 Space Complexity: O(m × n) ✨ Key Takeaway: This problem taught me how powerful DP can be in handling complex pattern-based problems, especially when multiple possibilities (like zero or multiple occurrences) are involved. It’s a perfect mix of logic and structure — and very satisfying once it clicks! 🔥 #Day10 #100DaysOfCode #120DaysOfCode #LeetCode #DynamicProgramming #ProblemSolving #CodingChallenge #CPlusPlus #LearningEveryday #KeepCoding
To view or add a comment, sign in
-
-
Day 26 of #100DaysOfCode 🚀 Today's problem was all about balance — literally. 🔹 LeetCode 1941 — Check if All Characters Have Equal Number of Occurrences The task: Verify whether every character in a string appears the same number of times. At first glance, it looks simple — but it's a great exercise in clean logic, frequency counting, and edge-case handling. 🧠 Approach (Java): Use an array of size 26 to store character frequencies. Track the first non-zero frequency. Compare all other non-zero counts with it. If any mismatch occurs → return false. Otherwise, the string is perfectly balanced. A small problem, but a powerful reminder that clarity > complexity. Efficient logic and readable code always scale better in the long run. 💡 Key Takeaway Mastering these bite-sized logic checks builds strong intuition for: ✔ string manipulation ✔ hashing concepts ✔ pattern consistency ✔ frequency-based problem solving These fundamentals become the building blocks for bigger DSA challenges. #100DaysOfCode #Day26 #LeetCode #DSA #JavaDeveloper #CodingJourney #ProblemSolving #Programming #Strings #Hashing #LearningEveryday #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 22/30 – 30DaysOfDSAChallenge 🚀 🧠 Topic: Subsets (Power Set Generation) 📘 Concepts Covered: Recursion | Backtracking | Power Set Today I solved the Subsets problem, where the goal is to generate all possible combinations (subsets) of a given array. This problem is a classic example of recursive backtracking and helps in building a solid foundation for combinatorial logic. 🔹 Approach – Recursive Backtracking 💡 Logic: At each recursive step, decide whether to include or exclude the current element. When we reach the end of the array, one subset is complete and added to the result. This method explores 2ⁿ possible subsets efficiently. ⚙️ Time Complexity: O(2ⁿ) ⚙️ Space Complexity: O(2ⁿ * n) (for storing all subsets) ✅ Result: Accepted ✅ | Runtime: 0 ms 🟢 | Beats: 100% 🚀 ✨ Key Takeaway: Recursion becomes powerful when you break a problem into smaller, self-similar parts. Every inclusion or exclusion step leads you toward mastering backtracking and decision trees. #Day22 #30DaysOfDSAChallenge #LeetCode #Recursion #Backtracking #PowerSet #Subsets #ProblemSolving #CPlusPlus #CodingChallenge #DSA #Programming #CodeEveryday #DeveloperJourney #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 06/10 of Linked List Series: Delete a Node at the Beginning 🎯 Let’s understand the concept in a simple and beginner-friendly way 👇 🧠 Algorithm (Step-by-Step): 1️⃣ Start with the head of the linked list (first node). 2️⃣ Check if the list is empty — if yes, there’s nothing to delete. 3️⃣ If not empty, move the head pointer to the next node. 4️⃣ The old head node gets disconnected automatically (deleted). 5️⃣ Return the new head of the list. 💡 In short: Deleting at the beginning simply means — 👉 “Make the second node the new head of the list.” This is one of the simplest and most common operations in Linked Lists. 🔥 Stay tuned for the next part in the series! #CodeWithLakkojuEswaraSai #CodeWithLakkojuEswaraSai_LinkedList #10000Coders #LinkedList #DataStructures #LearnCoding #JavaForBeginners #ProgrammersLife #CodingCommunity #TechLearning #CodingJourney #DSASeries #Leetcode #JavaDeveloper #FullStackDeveloper
To view or add a comment, sign in
-
-
🚀 Today I learned something every developer should know! While pushing my project to GitHub, I accidentally uploaded my entire Python virtual environment (venv) — almost 50,000+ files 😅. This caused warnings, massive uploads, and slow commits. After debugging for hours, I finally understood: 🔹 You should never push your venv folder to Git 🔹 Only your source code + requirements.txt should go in the repo 🔹 Add venv/ in .gitignore to avoid tracking unnecessary environment files The moment I removed venv from Git and added it to .gitignore, everything became super smooth: ✨ Cleaner repository ✨ Faster commits & pushes ✨ Project is easier to clone and set up for others 💡 And the best part? Anyone can recreate the environment later using: python -m venv venv pip install -r requirements.txt 🔻 Key takeaway Sometimes you don’t learn from tutorials — you learn from mistakes. And that’s perfectly fine. Every bug, warning, and error helps you grow as a developer. 📌 If you're starting with Python, Git, or VS Code: Remember — push code, not the venv. #Python #Git #GitHub #DevLife #LearningInPublic #VSCode #100DaysOfCode #DeveloperJourney #SoftwareEngineering #Debugging #VirtualEnvironment
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