Data Structures & AlgorithmsHardTCS NQT · Accenture
Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are greater than 7, and report the count plus the index of the largest element overall.
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
The count of greater elements to the right of index 2 is 1 (only 8), and the maximum 9 sits at index 0. The sum of these two values is 1, which is the answer.
More Coding Interview Problems questions
- Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this…
- Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have…
- Problem: The product of the digits of 2^10 · 3^4 is computed (in decimal). What is that product?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is reduced by repeatedly removing the first two elements and appending their sum to the…
- Problem: For the sequence 2, 3, 5, 7, 11, …, the first 10 prime numbers are listed. What is the sum of the 10th and 7th primes in the list?
- Problem: A bitmask represents a subset of the 4 items {A, B, C, D} by bits 0–3. How many subsets have an even number of items and do NOT…