Data Structures & AlgorithmsHardTCS NQT · Accenture
A stack machine runs PUSH 3, PUSH 4, ADD, PUSH 5, MUL in order. The result is the value on top of the stack at the end. What is it?
- A. 33
- B. 39
- C. 35
- D. 70
Correct answer: C. 35
ADD leaves 7 on the stack, PUSH 5 puts 5 above it, and MUL multiplies the two top values to give 35. Forgetting that MUL pops two values leaves a larger stack than expected.
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
- How many index pairs i < j in the array [1, 3, 1, 2, 3, 3] have a[i] = a[j]?
- What is the sum of the XOR of every non-empty contiguous subarray of [1, 2, 3]?
- How many contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?
- How many ordered triples (i, j, k) of distinct indices in [2, 3, 5, 1, 4] satisfy a[k] = a[i] + a[j], counting each unordered pair {i, j}…
- What is the length of the longest prefix of the string ababbaba that is itself a palindrome?
- An LRU cache of capacity 2 receives the request sequence 2, 1, 2, 3, 1, 2. A request is a hit if its key is cached. How many hits occur?