Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A sorted list has values 3, 7, 7, 9, 12, 12, 12, 15. How many distinct values lie within the range [7, 12] inclusive?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Count distinct values, not positions, in the inclusive range. The values 7, 9 and 12 qualify, which makes three distinct values.
More Coding Interview Problems questions
- Problem: On a 3×3 grid, each cell is labelled with its row times column (1-indexed). The number of cells whose label is a perfect square…
- Problem: How many integers in [1, 100] have exactly 3 divisors? Run the code. python print(sum(1 for x in range(1, 101) if sum(1 for d in…
- Problem: What is the sum of the digits of 3^20? Run the code. python print(sum(int(c) for c in str(3 20))) What is printed?
- Problem: How many paths of length 3 exist in a complete graph K4 that start and end at different vertices? Run the code (count ordered…
- Problem: What is the number of integers in [1, 1000] whose digits are all odd? Run the code. python print(sum(1 for x in range(1, 1001) if…
- Problem: What is the length of the longest subarray of [5, 1, 4, 2, 3, 6] whose elements can be sorted to form consecutive integers? Run…