Removing Peaks for Lowest Price with Monotonic Stack

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

  • text

To view or add a comment, sign in

Explore content categories