Unwind a Large Position Across Time Slices With Convex Impact

Last updated: November 29, 2026

Quick Overview

You must sell Q units over T time slices; selling q units in slice t costs c[t] * q + k[t] * q^2 (spread plus temporary impact). Return the minimum total cost and the allocation, first with dynamic programming and then with a faster exact method.

Imc
Coding & Algorithms
Software Engineer
Imc
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


You must sell Q units over T time slices; selling q units in slice t costs c[t] * q + k[t] * q^2 (spread plus temporary impact). Return the minimum total cost and the allocation, first with dynamic programming and then with a faster exact method.

When a market maker like IMC accumulates inventory it has to hedge or unwind it without paying too much in spread and impact, and execution scheduling is a recurring internal problem. The interviewer wants a correct DP first, then the insight that convex costs make a greedy marginal-cost approach exact.

What the Interviewer Expects
  • Formulates a DP over slices and units sold
  • States the O(T * Q^2) complexity of the DP
  • Notices that per-slice cost is convex in q
  • Derives marginal cost c[t] + k[t](2q - 1) for the q-th unit
  • Proves or argues greedy optimality via exchange
  • Cross-checks DP and greedy on small inputs
Key Topics to Cover
dynamic programming
convexity
greedy
heaps
optimal execution
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle a per-slice volume cap?
  • What if impact is permanent and raises the cost of all later slices?
  • Q is 10 million shares. How do you avoid one heap operation per share?
  • How would you add a risk penalty for holding inventory longer?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs: integer Q >= 0, arrays c and k of length T with k[t] >= 0. Choose nonnegative integers q_t summing to Q minimizing ∑tctqt+ktqt2\sum_t c_t q_t + k_t q_t^2. Return the cost and the allocation....

High-Level Design

DP. dp[j] is the minimum cost to have sold j units after processing some prefix of slices. For each slice, try every q. This is simple and correct but O(T * Q^2).

Greedy. The cost of the q-...


Submit Your Answer
Markdown supported

Related Questions