Data Structures & AlgorithmsModerateIBM · Deloitte pattern
A stack-based checker is run on four strings. Which one is balanced?
- A. (()[]{}
- B. {[}]()
- C. ([)]{}
- D. {[()()]}[(())]
Correct answer: D. {[()()]}[(())]
In ([)]{} the ) arrives while [ is on top; {[}] has the same crossing; (()[]{} ends with one ( left on the stack. Only {[()()]}[(())] closes every bracket in reverse order of opening. Equal counts of each bracket type are not enough.
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
- A circular queue in an array of size 6 uses front (index of the first item) and rear (index of the next free slot), both starting at 0…
- A 2-D array A[10][20] (indices from 0) of 4-byte integers is stored in COLUMN-major order starting at address 1000. What is the address of…
- Only the lower triangle (including the diagonal) of a 10 × 10 matrix is stored, row by row, in a 1-D array starting at address 2000, with…
- What is printed? (Python) python a = [3, 8, 1, 9, 4] a.insert(2, 7) a.pop() a.remove(9) print(a, len(a))
- A circular queue of size N = 5 keeps one slot empty. What is printed (dequeued values, 'F' for each rejected enqueue, final count)? c…
- Keys 50, 700, 76, 85, 92, 73, 101 are inserted into a hash table of size 7 with h(k) = k mod 7 and linear probing. What is the final table…