Link to the code: https://pastebin.com/SBtvXV3k
Link to the question: https://leetcode.com/problems/remove-k-digits/
**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 :
https://www.youtube.com/channel/UC5KbhWY7vCOEz_dMWX1t3nA
LeetCode Playlist: https://www.youtube.com/watch?v=secuBlDy0YQ&list=PLk3HmtBxW9XXxugG2k_ApmS3otqnH3Bow&index=2&t=0s
Download
0 formats
No download links available.
Remove K Digits | remove k digits | remove k digits leetcode | leetcode 402 | NatokHD