Count Bounded Buy-and-Sell Sequences
Company: Optiver
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: You start with k shares. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.
Constraints
- 0 <= n, k <= 200 and 0 <= m <= 200.
- Every transaction changes holdings by exactly one, and every sequence prefix must keep holdings nonnegative.
- All sequence lengths from zero through m qualify, and the exact answer is at most 2^53 - 1.
Examples
Input: (2, 1, 3)
Expected Output: 4
Explanation: One length-one and three valid length-three sequences end at two shares.
Input: (0, 0, 0)
Expected Output: 1
Explanation: The empty sequence is counted when initial and target holdings agree.
Hints
- Test zero allowed days with equal and unequal initial and target holdings.
- Include a target farther from the start than the day limit and cases that begin at zero holdings.
- Check both exact-length parity effects and the maximum holding/day boundaries.