Data Structures & AlgorithmsModerateGATE CS · TCS NQT
A stack starts empty. The operations are ['push', 'push', 'pop', 'push', 'push', 'pop', 'push', 'push', 'push', 'pop', 'push']. How many times does the stack height reach a NEW maximum (a height strictly greater than every height reached before)?
- A. 7
- B. 6
- C. 5
- D. 4
Correct answer: C. 5
Track the running height and the best height so far, and count each push that makes a new record. Counting pushes overall, or counting heights above zero, measures something else.
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
- From "bcabcdbac" delete exactly 3 letters (the rest keep their order). What is the lexicographically LARGEST string you can obtain?
- In [3, 4, 9, 5, 6, 2, 1, 7, 8], what is the length of the longest subsequence (keeping the order) in which every pair of consecutive…
- What is the minimum number of pieces needed to split "abacdcbaxyzyx" into contiguous pieces where every piece is a palindrome?
- You may increase any element of [5, 3, 2, 10, 4] by any amount (increases only). What is the minimum total increase needed to make the…
- A path of length 9 is walked from 0 to 9: a step of 1 costs 3 and a step of 2 costs 5. What is the minimum total cost?
- A 1 × 11 strip must be covered exactly by tiles of lengths 2, 3 and 5 (tiles cannot overlap or stick out). Tile lengths 2, 3, 5 cost 4, 5…