Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: From the list [5, 3, 3, 7, 12, 9], what is the second-smallest distinct value (duplicates count once)?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Remove duplicates, sort, and read the second value. Taking the second element of the sorted list with duplicates gives 3 instead of the second distinct value.
More Coding Interview Problems questions
- Problem: In the array [1, −2, 3, −4, 5, −6], how many contiguous subarrays have a sum of exactly 0?
- Problem: The mapping of letters is A=1 through Z=26. What is the sum of the values of the letters in the word "MATH"?
- Problem: The number of ways to choose 4 people from 9 so that a specific two people are never both chosen is what value?
- Problem: How many integers in [1, 10^4] are divisible by 3 and have an odd number of digits? Run the code. python print(sum(1 for x in…
- Problem: What is the number of distinct subsets sums obtainable from {2, 3, 7} (including the empty subset)? Run the code. python from…
- Problem: What is the largest prime factor of 2^20 - 1? Run the code. python n = 2 20 - 1 f = 2 last = 1 while f f <= n: while n % f == 0…