Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: In the array [9, 3, 7, 3, 9, 1, 7], how many elements are equal to the maximum of the elements to their right (the last element counts as having nothing to its right, so it is excluded from the count)?
- A. 2
- B. 0
- C. 3
- D. 1
Correct answer: D. 1
For each index compare the element with the maximum of its suffix to the right. Counting elements that are greater than everything to their right (strict leaders) gives a different number.
More Coding Interview Problems questions
- Problem: Start with the empty stack. Process the string "7 3 2 + 5 -" as postfix tokens (numbers are pushed, operators pop two values…
- Problem: The circular array [3, 1, 4, 2] has a 'next' pointer from each index i to (i+1) mod 4. Starting at index 0 and jumping by the…
- Problem: A stack of plates is filled by pushing 1 to 6 in order and popping after each push whenever the top is even. The final stack…
- Problem: A grid of 4×4 cells holds the value r + c (0-indexed). Starting from the top-left corner, what is the maximum total of values…
- Problem: A string is compressed by replacing each maximal run of equal letters with the letter and its count, only when the count is at…
- Problem: Pancake sort uses only prefix reversals on [3, 1, 2]. For each size from n down to 2, bring the largest value of the unsorted…