Rebalance a Model Portfolio Using Whole-Share Trades

Last updated: November 29, 2026

Quick Overview

Given current share holdings, cash, prices and target weights, compute the whole-share buy and sell quantities that bring the portfolio as close to target as possible without spending more cash than the portfolio has.

BlackRock
Coding & Algorithms
Software Engineer
BlackRock
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given current share holdings, cash, prices and target weights, compute the whole-share buy and sell quantities that bring the portfolio as close to target as possible without spending more cash than the portfolio has.

Model-based rebalancing is core to Aladdin Wealth and to the model portfolios BlackRock offers advisors. The interviewer wants to see the candidate reason about rounding to whole shares, a cash constraint, and a sensible greedy rule for leftover cash.

What the Interviewer Expects
  • Computes NAV including cash and current holdings
  • Floors target shares first so cash is never overspent
  • Distributes leftover cash greedily to the most underweight names
  • Handles tickers held but absent from the model (sell to zero)
  • Explains why greedy is a heuristic and not always optimal
Key Topics to Cover
greedy algorithms
rounding
portfolio rebalancing
cash constraints
floating point
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 add a minimum trade size so you skip tiny trades?
  • How would taxes on realized gains change the objective?
  • What if fractional shares are allowed for some accounts?
  • How would you rebalance 2 million advisor accounts overnight?
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: nav_cash, holdings (ticker to shares), prices, targets (weights summing to at most 1). Output: share deltas, positive to buy and negative to sell, only for tickers that change. Whole s...

High-Level Design
  1. NAV is cash plus the value of all holdings.
  2. Ideal shares for each name are target * NAV / price; floor them, which guarantees we do not overspend.
  3. Leftover cash is spent one share at a time...

Submit Your Answer
Markdown supported

Related Questions