Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A stack of plates is filled by pushing 1 to 6 in order and popping after each push whenever the top is even. The final stack, read from bottom to top, is what?
- A. [1, 3, 4]
- B. [2, 4, 6]
- C. [1, 3, 5]
- D. [1, 3, 5, 6]
Correct answer: C. [1, 3, 5]
Simulate the push and conditional pop exactly. Popping before pushing changes which values remain on the stack.
More Coding Interview Problems questions
- Problem: A grid of 4×4 cells holds the value r + c (0-indexed). Starting from the top-left corner, what is the maximum total of values…
- Problem: A string is compressed by replacing each maximal run of equal letters with the letter and its count, only when the count is at…
- Problem: Pancake sort uses only prefix reversals on [3, 1, 2]. For each size from n down to 2, bring the largest value of the unsorted…
- Problem: In the array [2, 7, 11, 15, 3, 8], how many pairs i < j have a[i] + a[j] equal to a multiple of 5?
- Problem: The binary search for a value in the sorted array [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] is run with the standard midpoint mid =…
- Problem: The bit string 1011001 is read as a binary number. What is its value when each bit is XOR-ed with the previous bit (the first bit…