← Hudson River Trading Interview Insights
The word 'amplitude' threw me off at first, took me a beat to realize it just meant the range.
Recognize that removing exactly K contiguous elements leaves a contiguous subarray of length n-K. The problem reduces to finding a contiguous subarray of length n-K with minimum difference between its maximum and minimum. Use a sliding window with a data structure that supports efficient insertion, deletion, and min/max queries, such as two monotonic deques or a balanced BST.
Pro tip: Clarify edge cases upfront: if K >= n, the array becomes empty (amplitude 0); if K = 0, return the original amplitude. Also discuss trade-offs between O(n log n) and O(n) approaches, showing awareness of practical performance.
Restate that removing K contiguous elements is equivalent to selecting a contiguous subarray of length n-K. The goal is to minimize the amplitude of that subarray.
Decide between a sliding window with monotonic deques (O(n)) or a balanced BST (O(n log n)). Explain the trade-offs and pick one based on constraints.
For sliding window: maintain two deques for min and max, slide the window of size n-K, and track the minimum difference. For BST: insert first n-K elements, then slide by removing left and adding right, querying min and max each time.
Check if K >= n (return 0), K = 0 (return original amplitude), and ensure the window size is valid. Also consider negative numbers and duplicates.
State time and space complexity. Walk through a small example to verify correctness, and discuss potential optimizations or alternative solutions.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.