FastPrepFractional Share Inventory Flattening
Problems/Fractional Share Inventory Flattening

Fractional Share Inventory Flattening

Robinhood logoRobinhood● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Robinhood can trade only whole shares with an exchange, while customers may buy or sell fractional shares. Maintain the firm's retained fractional inventory for each symbol while processing orders in order.

Every inventory row is symbol/quantity. Every order is symbol/side/quantity/currentPrice, where side is B for a customer buy or S for a customer sell. Numeric fields are fixed-point integers whose final two digits are fractional: 50 means 0.50 shares and price 1000 means $10.00. A quantity beginning with $ is a dollar amount; convert it to hundredths of a share as dollarCents * 100 / priceCents.

  • A customer buy removes the requested quantity from firm inventory.
  • A customer sell adds it.
  • After each order, immediately buy or sell enough whole shares at the exchange that retained inventory is in [0,100) hundredths.

Return final rows in the same symbol order and format as inventory.

Function

flattenFractionalInventory(orders: String[], inventory: String[]) → String[]

Examples

Example 1

orders = ["AAPL/B/150/1000","AAPL/B/40/1000","AAPL/B/50/1000"]inventory = ["AAPL/0"]return = ["AAPL/60"]

The retained inventory becomes 50, then 10, then 60 hundredths after whole-share flattening.

Example 2

orders = ["AAPL/S/75/1000","AAPL/S/50/1000","GOOGL/B/$21/100"]inventory = ["AAPL/0","GOOGL/75"]return = ["AAPL/25","GOOGL/54"]

AAPL sells one accumulated whole share to the exchange. The dollar order equals 21 hundredths of GOOGL.

Constraints

  • 1 <= inventory.length, orders.length <= 100000.
  • Inventory contains every ordered symbol exactly once and starts in [0,100).
  • Every dollar quantity converts exactly to a whole number of hundredths of a share.
  • All intermediate fixed-point values fit signed 64-bit integers.

More Robinhood problems

  • Top Ten Most Frequent Words in a BookPHONE SCREEN · Seen Oct 2026
  • Unique Transitive Dependent CountsPHONE SCREEN · Seen Sep 2026
  • Friendship and Balance TrackerONSITE INTERVIEW · Seen Sep 2026
All Robinhood interview questionsSee Robinhood hiring insights
Saved
class Solution {
    public String[] flattenFractionalInventory(String[] orders, String[] inventory) {
        // Write your solution here.
    }
}
Checking account…