Data Structures & AlgorithmsHardTCS NQT · Infosys
Push and pop operations on an initially empty stack are: push, push, pop, push, push, push, pop, pop, push. What is the maximum height the stack ever reaches?
- A. 4
- B. 5
- C. 6
- D. 8
Correct answer: A. 4
The height goes 1, 2, 1, 2, 3, 4, 3, 2, 3, so the peak is 4. The final height 3 is not the maximum.
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
- Customers arrive at times 0, 1, 2 and 5 and need service times 3, 2, 1 and 2 on a single server (first come, first served; a customer…
- For the same four customers (arrivals 0, 1, 2, 5; service times 3, 2, 1, 2) on a single first-come-first-served server, what is the…
- A list holds 1 to 9 in order. The first 4 nodes are reversed, then the node with value 6 is deleted. What is the value at position 5 of…
- How many contiguous subarrays of [1, 2, -3, 3, -3, 2, 1] have sum exactly zero?
- How many index pairs i < j in [1, 3, 5, 7, 9, 4] have |a[i] - a[j]| = 2?
- How many distinct values appear among the XORs of all non-empty contiguous subarrays of [1, 2, 3]?