FastPrepCapital Gains Tax from Trades
Problems/Capital Gains Tax from Trades

Capital Gains Tax from Trades

Arcesium logoArcesium● MediumINTERNFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Arcesium intern or full-time online assessment. The source code shows that sold lots are matched first in, first out. The report gives the rule for losses. The source does not say how to round fractions of a cent. We chose that. Our version is about 95% the same as the reported question.

Process chronological stock trades and calculate the tax on realized profit. Each trade is a comma-separated string:

date,ticker,side,shares,price
  • side is B for a buy or S for a sell.
  • shares is a positive integer.
  • price is a non-negative decimal amount with at most two digits after the decimal point.

Track positions separately by ticker and match closing shares against open lots in first-in, first-out order. A sell closes long shares before opening a short position; a buy closes short shares before opening a long position. A single trade may close an existing position and open the opposite position with its remaining shares.

For a closed long share, realized profit is sell price - buy price. For a closed short share, realized profit is short-sale price - cover price. Open lots do not contribute realized profit.

Add realized profit across every ticker. Tax is 25% of the positive total; when the total is zero or negative, tax is zero. Return the tax as US currency with a leading $, comma separators, and exactly two decimal places.

Function

calculateTax(trades: String[]) → String

Examples

Example 1

trades = ["2024-01-01,ABC,B,10,100.00","2024-01-02,ABC,S,4,120.00"]return = "$20.00"

Selling four shares realizes 4 * (120 - 100) = $80. Tax is 25%, or $20.00.

Example 2

trades = ["2024-01-01,ABC,S,5,50.00","2024-01-02,ABC,B,5,60.00"]return = "$0.00"

Covering the short realizes a loss of 5 * (50 - 60) = -$50, so the tax is zero.

Constraints

  • trades.length >= 1.
  • Trades are ordered chronologically.
  • Every trade uses the five-field format described above.
  • Every testcase produces a tax amount that is an exact number of cents.

More Arcesium Online Assessment questions

  • City Infection NumberOA · Seen Jul 2025
  • Minimum Tunnel Crossing TimeOA · Seen Jul 2025
  • Product of Subset MaximaOA · Seen Jul 2025
  • Reconstruct the Root StreamOA · Seen Jul 2025
  • Add DigitsOA · Seen Aug 2023
  • Binary Tree Maximum Path SumOA · Seen Aug 2023
  • Detect a Cycle in Directed Hate RelationshipsOA · Seen Aug 2023
  • Reverse First K Characters in Every 2K BlockOA · Seen Aug 2023
  • Robo Data Sharing DirectionOA · Seen Jul 2023
  • K-th Character in an Infinite StringOA · Seen Aug 2020

Similar questions at other companies

  • Incident MonitorStripe · OAStripe interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Random Picks Excluding Recent ValuesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Realized PnL with Oldest Inventory FirstBelvedere Trading · OA
  • Process Banking OperationsVercel · OA
  • Buffet Day GainsUpstart · OAUpstart interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Count House Segments After Sequential DestructionByteDance · OAByteDance interview questions
All Arcesium interview questionsSee Arcesium hiring insights
Saved
class Solution {
    public String calculateTax(String[] trades) {
      // Write your code here.
    }
}
Checking account…