Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it. How many elements are visible from the left?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
Track the running maximum and count strictly larger elements. Counting elements greater than the first element alone gives a different number.
More Coding Interview Problems questions
- Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).
- Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the…
- Problem: How many trailing zeros does 1000! have in base 10?
- Problem: The string "BANANA" has how many distinct arrangements of its letters (letters are identical when they match)?
- Problem: For the word-count test: how many distinct strings can be formed by rearranging "AABBCCD" so that no two identical letters are…
- Problem: A game uses 5 players in a circle numbered 1 to 5. The player with the ball passes it 3 positions clockwise each turn (the ball…