Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
From the number 1432219 you must delete exactly 3 digits (the remaining digits keep their order). What is the smallest number you can obtain, written without leading zeros?
- A. 2219
- B. 12219
- C. 1219
- D. 1221
Correct answer: C. 1219
Use a monotonic stack: while the top digit is larger than the current digit and deletions remain, pop it. Deleting the first k digits or the largest digits one at a time misses the case where a smaller digit appears later.
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
- What is the minimum number of swaps of two (not necessarily adjacent) elements needed to sort the array [4, 3, 2, 1, 6, 5] into increasing…
- People weigh [3, 5, 3, 4, 2, 7, 1] kg. Each boat carries at most two people and at most 9 kg in total. What is the minimum number of boats…
- Children stand in a row with ratings [1, 2, 2, 5, 4, 3, 3, 8, 1]. Each child gets at least one candy, and a child with a higher rating…
- Jobs of lengths [7, 6, 5, 4, 3, 3] are assigned to 2 identical machines. Each job runs on one machine without interruption. What is the…
- Intervals (half-open, [start, end)) are [(1, 3), (2, 4), (3, 5), (4, 6), (5, 7), (6, 8)]. What is the minimum number of intervals you must…
- Weighted jobs (start, end, weight) are [(1, 3, 5), (2, 5, 6), (4, 6, 5), (6, 7, 4), (5, 8, 11), (8, 9, 2)]. Two jobs are compatible when…