Data Structures & AlgorithmsHardProduct Company SDE · sliding window OA
Problem: Which technique counts subarrays with sum at most K in a non-negative array in O(n)?
- A. Sorting the array and binary searching each value
- B. Two pointers over a sliding window
- C. Dijkstra on prefix sums
- D. Floyd-Warshall on indices
Correct answer: B. Two pointers over a sliding window
With non-negative values the window sum is monotone in each pointer move, so the number of valid right ends for each left end is counted in one pass.
More Coding Interview Problems questions
- Problem: What is the time complexity of subset-sum over n items with a bitset of width W (up to 10^5)?
- Problem: What is the purpose of the low-link value in Tarjan's strongly connected components algorithm?
- Problem: What is the worst-case complexity of the SPFA (queue-based Bellman-Ford) shortest path algorithm?
- Problem: Which property must hold for Huffman coding to produce an optimal prefix code?
- Problem: What is the complexity of Kruskal's algorithm when edges are already sorted and union-find uses path compression and union by rank?
- Problem: What does the Kuhn-Munkres (Hungarian) algorithm compute on a bipartite graph with weights?