Data Structures & AlgorithmsVery hardGoogle · Stacks
A greedy stack algorithm removes exactly 3 digits from the number string "1432219" to get the smallest possible number (keeping the order of the remaining digits). What is the result?
- A. 1422
- B. 1219
- C. 1229
- D. 2219
Correct answer: B. 1219
Scan left to right and pop the stack top while it is larger than the current digit and removals remain: 4, 3 and one 2 are removed, leaving 1219.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A cache with 3 slots serves the page requests 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. How many misses occur under LRU replacement and under…
- What is the time complexity of reading the element arr[i] from an array of n elements, given i?
- Which data structure works on the Last In, First Out (LIFO) principle?
- What is the worst-case time complexity of binary search on a sorted array of n elements?
- Which of these sorting algorithms is stable in its standard implementation?
- What is the time complexity of inserting a new node at the head of a singly linked list of n nodes?