Remove K Digits | remove k digits | remove k digits leetcode | leetcode 402

Опубликовано: 14 Март 2026
на канале: Akshay Goyal
1,597
63

Link to the code: https://pastebin.com/SBtvXV3k
Link to the question: https://leetcode.com/problems/remove-...

*Complexity Analysis*
Time complexity :O(N). Although there are nested loops, the inner loop is bounded to be run at most k times globally. Together with the outer loop, we have the exact (N + k) number of operations. The time complexity of the main loop is bounded within 2N. For the logic outside the main loop, it is clear to see that their time complexity is O(N). As a result, the overall time complexity of the algorithm is O(N).
Space complexity: O(N). We have a stack that would hold all the input digits in the worst case.

SUPPORT MY WORK BY SUBSCRIBING TO THE CHANNEL :
   / @akshaygoyal2134  

LeetCode Playlist:    • Prison Cells After N Days | prison cells a...