Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: Consider the graph on vertices 1–6 with edges 1-2, 2-3, 3-4, 4-1, 5-6. What is the size of its largest connected component?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
There are two components, {1,2,3,4} and {5,6}, so the largest has four vertices. The 4-cycle 1-2-3-4 is the component that forms the answer.
More Coding Interview Problems questions
- Problem: Starting at index 0 of the array [2, 4, 1, 6, 3], repeatedly jump forward by the value at the current index (no wraparound; the…
- Problem: How many integers in the range 1 to 100 are both a multiple of 3 and have a digit sum equal to 6?
- Problem: The string "abcdefg" is rotated right by 3 positions. What is the first character of the rotated string?
- Problem: For the set {1, 2, 3, 4, 5, 6, 7, 8}, how many 3-element subsets have a sum that is even?
- Problem: In a list of 6 candidates, each candidate is either rejected or accepted. The number of ways to accept at least 2 and at most 4…
- Problem: A sequence is generated from 1 by repeatedly applying: x → x + (x mod 4). Starting at x = 1, what is the value after 6 steps?