Data Structures & AlgorithmsHardGATE CS · TCS NQT
Apply the operations push 3, push 5, pop, push 7, push 2, pop, pop to an initially empty stack. What is the sum of the values remaining on the stack?
- A. 4
- B. 3
- C. 0
- D. 17
Correct answer: B. 3
Simulate the stack: after the pops only 3 remains, so the sum is 3. Summing all pushed values (the last option) ignores the pops.
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
- Starting at step 0, you climb to step 6 taking steps of 1 or 2 each time. How many distinct sequences of steps are possible?
- How many integers from 1 to 1000 inclusive are divisible by 8 and have an even number of 1-bits in binary?
- Repeatedly merge two values into their sum at cost equal to that sum, starting from [1, 2, 3, 4]. What is the minimum total cost?
- How many integers from 1 to 100 inclusive have an odd number of positive divisors?
- What is the length of the longest common substring (contiguous) of "abcdef" and "zcdemf"?
- When converting the infix expression "(a+b)(c-d)/e" to postfix, how many operator symbols appear in the postfix output?