Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A linked list is written as values 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8. The list is reversed in groups of 3 (the last group of fewer than 3 nodes is left as is). What is the value of the 4th node (1-indexed) afterwards?
- A. 6
- B. 5
- C. 3
- D. 4
Correct answer: A. 6
Reversing in groups of 3 gives 3 → 2 → 1 → 6 → 5 → 4 → 7 → 8, so the 4th node is 6. Reading 0-indexed position 4 gives 5, reversing in groups of 2 gives 2 → 1 → 4 → 3 (3), and the unreversed 4th node is 4.
More Coding Interview Problems questions
- Problem: The regex-like string match: count the substrings of "aabbaab" that match the pattern a+b (one or more a's immediately followed…
- 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…