Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The array [5, 2, 8, 2, 9, 1, 5, 5] contains repeated values. How many distinct values appear exactly twice?
- A. 2
- B. 0
- C. 1
- D. 3
Correct answer: C. 1
Count occurrences of each value and tally those with exactly two. Value 5 appears three times, so it does not qualify; only 2 appears exactly twice.
More Coding Interview Problems questions
- Problem: What is the maximum sum of a subsequence of [4, −1, 2, 1] with no two adjacent elements chosen (the empty selection is not…
- Problem: The string "ABCABCABC" is read and each letter is replaced by its position in the alphabet (A=1, B=2, C=3). What is the sum of…
- Problem: From the list [12, 18, 24, 30, 36], what is the number of distinct prime divisors of the product of all five numbers?
- Problem: The array [7, 1, 5, 3, 6, 4] is processed to find the maximum profit from one buy and one later sell (0 if none). What is the…
- Problem: A grid of 3×3 cells is numbered 1 to 9 row by row. Starting at 1 (top-left), the robot moves right or down. The number of paths…
- Problem: A list of intervals is [1,5], [2,3], [4,8], [7,9], [10,11]. Merge all overlapping intervals (touching at an endpoint counts as…