Data Structures & AlgorithmsHardIBM · Deloitte pattern
Infix A * (B + C * (D − E)) / F is converted to postfix with an operator stack (operators and '(' are pushed onto it). What is the largest number of items on the stack at any moment?
- A. 3
- B. 6
- C. 4
- D. 5
Correct answer: B. 6
After reading the second '(' the stack holds *, (, +, *, ( (5 items), and pushing − makes 6. The output is A B C D E − * + * F /. Counting only operators and forgetting the parentheses gives 4.
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
- Using a sliding window, find the length of the longest substring with no repeated character in the string dvdfabcda.
- What is the length of the shortest contiguous subarray of [1, 4, 4, 2, 3, 1, 5] whose sum is at least 9?
- How many contiguous subarrays of [1, 2, 3, −3, 3, 1] have sum exactly 3? (A prefix-sum + hash-map method counts them in O(n).)
- How many UNIQUE triplets (as sets of values, ignoring order) of [−1, 0, 1, 2, −1, −4, −2, 3] sum to 0? (Sort + two pointers, skipping…
- What is the time complexity of this Java method? java String build(int n) { String s = ""; for (int i = 0; i < n; i++) s = s + "a"; return…
- In Python, a list q is used as a queue: items are added with q.append(x) and removed with q.pop(0). If n items pass through the queue…