Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A stream of 12 numbers 5, 1, 4, 4, 2, 5, 3, 1, 2, 3, 3, 4 arrives. How many distinct values appear at least twice in the stream?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Count the frequency of each value and tally those with frequency of at least two. Counting total repeated positions (occurrences beyond the first) is a different quantity.
More Coding Interview Problems questions
- Problem: Start with x = 5. Repeat this rule: if x is odd, set x = x + 3; if x is even, set x = 2x − 1. Count how many times the rule is…
- Problem: Starting from 0 on a number line, a frog jumps +4, then −1, then +4, then −1 and so on, alternating, for 25 jumps in total. It…
- Problem: Count the vertices of the tree with edges 0–1, 0–2, 1–3, 1–4, 2–5, 5–6, 5–7 whose removal leaves every remaining connected…
- Problem: Vertices 1–6 have these directed prerequisites: 1→4, 2→4, 2→5, 3→5, 4→6, 5→6. Among all valid topological orders, the…
- Problem: A graph on vertices 0–7 has edges 0-1, 1-2, 2-0, 3-4, 4-5, 5-6, 6-3, 6-7. The edges are removed one at a time in this order: 2-0…
- Problem: In a graph with vertices 0–6, each edge has weight 0 or 1. Edges: 0-1 (0), 0-2 (1), 1-3 (1), 2-3 (0), 3-4 (1), 4-5 (0), 2-6 (1)…