Data Structures & AlgorithmsHardTCS NQT · Infosys
Starting at index 0 of the array [4, 8, 5, 2, 25], repeatedly jump to the next strictly greater element (a monotonic stack gives these jumps). How many jumps are made before no greater element exists?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Jumps go 4 to 8 to 25. The element 5 is never reached because the chain skips it, so counting every element that is smaller than the target is wrong.
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
- What is the sum of the stock span values for prices [100, 80, 60, 70, 60, 75, 85]? The span of day i is the number of consecutive days…
- A queue is built from two stacks: enqueue pushes onto the inbox stack, and dequeue pops from the outbox stack, first transferring all…
- How many non-empty distinct palindromic partitions, i.e. ways to split the string aabb into contiguous pieces where every piece is a…
- How many distinct non-empty subsequences (as strings) does the word aba have?
- A print queue holds jobs with priorities [2, 1, 3, 2] (index 0 to 3). The front job prints only if no waiting job has a higher priority…
- 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?