Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Intervals [1,4], [3,7] and [6,10] are available. What is the minimum number of these intervals needed to cover the whole segment [1, 10] (every point from 1 to 10 must be inside a chosen interval)?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Point 5 lies only in [3,7], and point 6 lies in [3,7] and [6,10], so all three intervals are needed; dropping any one leaves a gap.
More Coding Interview Problems questions
- Problem: Starting from x = 7, apply six times the rule: if x is even, x = x/2 (integer), otherwise x = 2x + 3. What is the final value of x?
- Problem: The words of "the sky is blue" are put in reverse order and joined by single spaces to form a new string. How many characters…
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated left by 3 and then the first 4 elements are reversed. What is the element at index…
- Problem: The string "abcdefgh" is cut into pieces of length 3 from the left (the last piece may be shorter). The pieces are then sorted…
- Problem: Let g(n) be the number of integers in [1, n] whose decimal digit sum is even. What is g(50)?
- Problem: The Euler's totient of 36 is φ(36), the count of integers in [1, 36] coprime to 36. What is φ(36)?