Data Structures & AlgorithmsVery hardProduct company OA
Adjacent equal pairs are removed repeatedly with a stack until none remain. What is left of 'pqqprrsttsx'?
- A. ssx
- B. px
- C. x
- D. (empty)
Correct answer: C. x
Stack trace: p, q, q pops q → [p]; p pops p → []; r, r cancel; s; t, t cancel → [s]; s cancels s → []; x → [x]. Removing only the pairs visible in the ORIGINAL string (qq, rr, tt) and stopping leaves 'ppssx' → 'ssx' after one more round – the stack does all rounds in one pass.
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
- An array is split into the MAXIMUM number of contiguous chunks such that sorting each chunk separately and concatenating them gives the…
- An extended Boyer–Moore vote keeps two candidates to find every value occurring MORE than n/3 times, then verifies them with a second…
- Only the head pointer of a singly linked list of n nodes is known (no length is stored). What is the time to reach its middle node?
- An empty deque performs pushfront(1), pushfront(2), pushfront(3) and then popback(). Which value is removed?
- A sorted array holds n elements and has spare capacity. What is the worst-case time to insert a new element so that the array stays sorted?
- Counting sort on [2, 0, 2, 1, 0, 2] (values 0–2) builds count[v] and then turns it into cumulative counts, count[v] = number of elements ≤…