Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Starting with 8 singleton sets {0}..{7}, perform these unions in order: (0,1), (2,3), (1,3), (4,5), (6,7), (5,7), (3,4). After all unions, what is the size of the largest set?
- A. 4
- B. 8
- C. 1
- D. 7
Correct answer: B. 8
The first six unions build {0, 1, 2, 3} and {4, 5, 6, 7}; the final union (3, 4) joins them into one set of size 8. Stopping before the last union gives 4, reporting the number of sets gives 1, and 7 counts union operations.
More Coding Interview Problems questions
- Problem: A grid has '.' for open cells and '#' for walls: rows are ".#..#", ".#.##", "...#.", "##..#" and "#...." (5×5). Cells connect…
- Problem: How many simple cycles (cycles that visit no vertex twice, with 3 or more vertices) does the complete undirected graph K4 on…
- Problem: A rooted tree (root 1) has children lists: 1: [2, 3], 2: [4, 5, 6], 3: [7], 4: [], 5: [8], 6: [], 7: [9], 8: [], 9: []. How many…
- Problem: For the same rooted tree as the previous question (root 1: children 2, 3; 2: children 4, 5, 6; 3: child 7; 5: child 8; 7: child…
- Problem: In a binary tree with 7 nodes in level order [10, 5, 15, 2, 7, 12, 20] (missing children are shown as absent, so the array…
- Problem: Three sorted rows are [1, 5, 9, 14], [2, 6, 10, 15] and [3, 7, 11, 16]. Merging all rows into one sorted sequence, what is the…