Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A stack-based bracket checker reads the string "([]{()})[" and reports the number of unmatched opening brackets at the end (0 if the string is fully matched).
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Push openers and pop on matching closers; whatever remains on the stack is unmatched. Here the trailing '[' is the only unmatched opener.
More Coding Interview Problems questions
- Problem: An LRU cache of capacity 2 handles requests 1, 2, 1, 3, 2, 1, 4. Each request that is not cached causes a miss and evicts the…
- Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?
- Problem: A string of length 6 is formed using letters only from {a, b}, containing no substring "aa" or "bb". How many such strings are…
- Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3…
- Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?