Data Structures & AlgorithmsHardProduct Company SDE · data structures
Problem: What is the time complexity of building a Fenwick tree from an array of n values in O(n) time?
- A. Linear, by adding each value to its parent node once
- B. O(n log n) only
- C. O(n^2)
- D. Impossible in linear time
Correct answer: A. Linear, by adding each value to its parent node once
Each index pushes its value to i + lowbit(i) once, giving a linear-time build.
More Coding Interview Problems questions
- Problem: What does the Booth's algorithm compute?
- Problem: Which claim about the Manacher algorithm is correct?
- Problem: Which concept is used by the Rabin-Karp algorithm to compare substrings in constant time?
- Problem: What is the number of comparisons needed by heapsort in the worst case for n elements?
- Problem: Which algorithm finds the k-th smallest element in expected linear time?
- Problem: Which property does the KMP failure function of a string satisfy?