Day 23: LeetCode 1047 - Remove Adjacent Duplicates with Stack

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

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories