Day 13/45: Remove K Digits 🚀 The Concept: 🛒 Imagine a Price Tag with a character limit. To get the lowest price, you don't just remove the biggest numbers—you remove the "peaks" that appear early on. What I Learnt: 🧠 Monotonic Stack: The best way to "look back" and remove larger numbers in O(n) time. Greedy Logic: Always prioritize fixing the leftmost digits to minimize the total value. How I Did It: 🛠️ Used a string-based stack to maintain an increasing order. Popped the stack when a smaller digit arrived. Handled leading zeros and empty results. Stats: 1ms (Top 75%) | Memory: Top 90%! #100DaysOfCode #LeetCode #Coding #CPP
Removing Peaks for Lowest Price with Monotonic Stack
More Relevant Posts
-
Day 23 of #100DaysOfCode: #DSA: Stack: 1. Simple Stack 2. Monotonic stack: Stores items in sorted order(strictly increasing/decreasing) 3. Greedy Stack: pop/push based on greedy decisions to build an optimal result. Leetcode Problem: - Remove All Adjacent Duplicates(1047) approach: - use stack - assume first item is unique and add it to the stack - now iterate over the string - if stack top == current char then pop (it's adjacent and duplicate remove them) - else push current char - build final string from the stack and return it Time Complexity: O(n) Space Complexity: O(n) #Coding #CodingJourney
To view or add a comment, sign in
-
-
Day 19 Of #100DaysOfCode: #DSA: Solve leetcode problem with Merge Intervals Pattern - Insert Intervals(medium 57) Approach: - Sort the array by start time - create a temp vector/array - now iterate over intervals and check for each interval if its start time is greater then the newInterval start time if it is then add newInterval into the temp else add curr interval - now merge the intervals that are stored in temp vector/array Time Complexity: O(n logn) Space Complexity: O(n) #Coding #LearnInPublic #CodingJourney
To view or add a comment, sign in
-
-
In Go, you can read from files, network connections, HTTP request bodies, and even strings using the same code. The secret is io.Reader. The io.Reader interface describes where data comes from, not how it is stored. If a type knows how to provide bytes when asked, it implements io.Reader. Your function accepts io.Reader, and suddenly it works everywhere. This is interface-based design in action. Your code depends on behaviour, not concrete types. Read once, use everywhere. Follow me for more Go bytes #golang #golangtips #goprogramming #coding #softwaredevelopment
To view or add a comment, sign in
-
-
POST 2: First Stack Problem Solved 🎯 DSA Progress | First Stack Problem Solved Solved my first problem using the **Stack approach** today. Key learnings: ✅ Stack helps manage order efficiently ✅ Pushing and popping at the right time is crucial ✅ Visualizing the stack state avoids logical errors This problem helped me understand why Stack is preferred over brute force in many scenarios. #DSA #Stack #ProblemSolving #DSAJourney #Coding
To view or add a comment, sign in
-
LeetCode POTD: Minimum Difference Between Highest and Lowest K Scores Intuition: The goal is to pick k scores such that the difference between the maximum and minimum is minimized. After sorting the array, this becomes straightforward. For any window of size k: The maxi is at the right end - nums[i] The mini is at the left end - nums[i - k + 1] We slide this window across the array and keep updating the minimum difference. This works because sorting ensures elements inside each window are in ascending order. Time Complexity: O(n log n) The detailed thought process and example are explained in the notes below 👇 #leetcode #potd #problemsolving #coding #slidingwindow #twopointers #consistency
To view or add a comment, sign in
-
-
Day 14/45 of my DSA Challenge 🚀 Today's trio: LeetCode 34, 35, 704 - all about Binary Search variations! Here's what clicked for me: Binary Search isn't just about finding an element. It's about finding BOUNDARIES. 🎯 Quick question for fellow coders: What's trickier for you? 🔹 Getting the mid calculation right 🔹 Handling the left/right pointer updates 🔹 Edge cases (empty arrays, single elements) Drop your answer below! Let's learn from each other. Day 14 done. 31 more to go. The consistency is building momentum! 💪 #DSAChallenge #LeetCode #CodingJourney
To view or add a comment, sign in
-
Day 36 – Removing Elements from a Linked List 🔗✂️ Today’s focus was a clean linked list manipulation task: Remove Linked List Elements. Traversed the list with pointer tracking, skipping and unlinking nodes matching the target value. Handled edge cases like head removal and consecutive target nodes, achieving O(n) time with O(1) space. A straightforward exercise in pointer discipline and iterative list surger sometimes simplicity reinforces the fundamentals. 💻 #LeetCode #LinkedList #Pointers #Algorithms #Coding #100DaysOfCode
To view or add a comment, sign in
-
Day 30 – Navigating Binary Search Tree Minimality 🌳🎯 Today's focus was a single, precise problem exploring the intrinsic order of binary search trees to find minimal distance between node values, emphasizing efficient traversal and in-order property utilization. 🎯 Minimum Distance Between BST Nodes Leveraged the BST property that in-order traversal yields sorted values. Conducted an in-order traversal recursively or iteratively while tracking the previous visited node’s value, computing the difference with each new node, and maintaining the global minimum. Achieved O(n) time with O(h) space (recursion stack), where n is node count and h is tree height. On this milestone day, a single problem reinforced a fundamental principle: sometimes the most efficient path is already embedded in the structure itself. Progress isn't just about solving more it's about seeing deeper. 💻 #LeetCode #Coding #Algorithms #DataStructures #BinarySearchTree #BST #InOrderTraversal #TreeTraversal #ProblemSolving #SoftwareEngineering #Programming #100DaysOfCode
To view or add a comment, sign in
-
#Day502 of #600DaysOfDSA Topics and Learnings: #LinkedList, #2Pointers Problems Re-revised: 122. #LeetCode #19 : Remove Nth Node From End of List Approach: Used #TwoPointers to solve this Complexity Analysis: TC: O(N) SC: O(1) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
LeetCode Daily Problem (26th Jan 2026) Educational Insight - The "1200. Minimum Absolute Difference" problem showcases a simple yet powerful pattern: sort first, then compare neighbors to derive the tightest gaps between numbers. Sorting guarantees that any minimal absolute difference appears between adjacent elements, allowing a clean two‑pass implementation that returns all optimal pairs. Key Implementation Details Sort the input array arr in ascending order. Single pass to compute minDiff over |arr[i] − arr[i−1]| for all i ≥ 1. Second pass to push every pair [arr[i−1], arr[i]] whose difference equals minDiff. Complexity: O(n log n) time, O(1) extra space beyond result storage. Full platform dropping soon. Stay tuned. Join the waitlist: https://lnkd.in/ge3vvHFu #DSA #LeetCode #Coding #VisuallyInclined
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