Data Structures & AlgorithmsVery hardProduct company OA
A stack-based decoder expands k[s] into s repeated k times (nesting allowed). What does '2[x3[y]z]q' decode to?
- A. xyyyzqxyyyzq
- B. xyyyzxyyyzq
- C. xyzxyzxyzq
- D. xyyyzq
Correct answer: B. xyyyzxyyyzq
Innermost first: 3[y] = yyy, so the bracket is xyyyz; 2[…] doubles it to xyyyzxyyyz; q lies outside every bracket and is appended once. Applying 2 to the trailing q as well gives xyyyzqxyyyzq; repeating 'xyz' three times gives xyzxyzxyzq.
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
- Adjacent equal pairs are removed repeatedly with a stack until none remain. What is left of 'pqqprrsttsx'?
- 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?