Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: The regex-like string match: count the substrings of "aabbaab" that match the pattern a+b (one or more a's immediately followed by exactly one b, as contiguous substrings).
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Each match is one or more a's directly followed by a b, so the 'aab' at the start and the 'aab' near the end are the two matches. Counting the b characters alone gives 3, including the lone b that has no a before it.
More Coding Interview Problems questions
- Problem: Starting from the tree with root 1 and children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7], a DFS visits children in increasing order…
- Problem: For each index of a = [4, 5, 2, 10, 8], find the index of the nearest element to its left that is strictly smaller (or -1). Run…
- Problem: A directed flow network has source s = 0 and sink t = 3 with arcs and capacities: 0→1 (3), 0→2 (2), 1→2 (1), 1→3 (2), 2→3 (3)…
- Problem: A bottleneck path from vertex 0 to vertex 4 minimises the largest edge weight used. Using the undirected edges 0-1 (7), 1-2 (3)…
- Problem: A DAG has 4 vertices with edges 0→2 and 1→2 and 2→3 (vertices 0, 1 have no incoming arcs). How many distinct topological orders…
- Problem: In the undirected graph on vertices 0–4 with edges 0-1, 0-2, 1-2, 1-3, 2-3, 3-4, how many Hamiltonian paths exist (paths that…