Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: For the array [1, 3, 5, 7, 9], how many subarrays have an average equal to 5?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
A subarray has average 5 when its sum equals 5 times its length. Checking the subarray [5] and the subarrays [3, 5, 7] and [1, 3, 5, 7, 9] (the centred ones) gives the count.
More Coding Interview Problems questions
- Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?
- Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the…
- Problem: The complete directed graph on 4 vertices has an arc in both directions between every pair of distinct vertices. How many…
- Problem: The path graph P4 has vertices 1–4 and edges 1-2, 2-3, 3-4. How many edges does its complement graph (on the same vertices…
- Problem: A complete binary tree has 15 nodes (height 3, all levels full). How many of its nodes are leaves?
- Problem: The string "abba" has how many palindromic substrings (counted by index range)?