Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Counting sort is applied to [3, 1, 2, 3, 0, 1] with keys in the range 0 to 3. After counting occurrences and computing prefix sums, the stable output array is built. What is the position (0-based) of the first occurrence of the value 3 in the output?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
The output positions of a value start after all smaller values; there are 1 + 2 + 1 = 4 elements smaller than 3 (values 0, 1, 1 and 2), so the first 3 lands at index 4.
More Coding Interview Problems questions
- Problem: The string "aaabbcccc" has its runs counted. What is the length of the longest run of identical characters?
- Problem: How many integers from 1 to 300 are divisible by 4 or 6 but not by 12?
- Problem: A list of numbers is [10, 4, 9, 7, 5, 12]. A "peak" is an element strictly greater than both of its neighbours (end elements have…
- Problem: The string "racecarxyz" is examined for palindromic substrings of length at least 5. How many such palindromic substrings are…
- Problem: The number of ways to arrange the letters of "LEVEL" so that the two E's are not adjacent is what value?
- Problem: Consider the sequence 1, 4, 9, 16, … of perfect squares. What is the smallest square that is greater than 500 and also ends in…