FastPrepCount Bounded Share Transactions
Problems/Count Bounded Share Transactions

Count Bounded Share Transactions

Optiver logoOptiver● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Optiver online assessment. The report gives the share changes, the rule that the count never goes below zero, the goal of counting sequences up to a given length, and a worked example. It does not give the function signature or the input limits. We added those. Our version is about 97% the same as the reported question.

You start with startShares shares. One transaction does exactly one of the following:

  • buy one share, increasing the holding by one; or
  • sell one share, decreasing the holding by one, provided the holding is positive before the sale.

Count all distinct transaction sequences whose length is between 0 and maxTransactions, inclusive, and that finish with exactly targetShares shares. The empty sequence counts when the starting and target holdings are equal.

Return the total number of valid sequences.

Function

countTransactionSequences(startShares: int, targetShares: int, maxTransactions: int) → long

Examples

Example 1

startShares = 1targetShares = 2maxTransactions = 3return = 4

One one-transaction sequence and three three-transaction sequences finish at two shares: B, BBS, BSB, and SBB.

Example 2

startShares = 0targetShares = 0maxTransactions = 2return = 2

The empty sequence and BS are valid. A sequence cannot begin with a sale at zero shares.

Constraints

  • 0 <= startShares <= 60
  • 0 <= targetShares <= 60
  • 0 <= maxTransactions <= 60
  • The answer fits in a signed 64-bit integer.

More Optiver Online Assessment questions

  • Overheat Prevention ControllerOA · Seen Nov 2026
  • Power Cell BankOA · Seen Nov 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
  • Fastest Average Speed over a Rolling KilometerOA · Seen Sep 2026
  • Multi-Level Inventory Storage SystemOA · PHONE SCREEN · Seen Aug 2026
  • Proportional Momentum Investment StatisticsOA · Seen Aug 2026
  • Count Ordered Size SequencesOA · Seen Aug 2026
  • Profitable Currency Exchange CycleOA · Seen Aug 2026
  • Construct Binary Tree S-ExpressionOA · Seen Jul 2026
  • Days BetweenOA · Seen Jul 2026

Similar questions at other companies

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
  • Count Combinations Using Weights One Through KConfluent · OAConfluent interview questions
  • ABO Parent Genotype CombinationsUpstart · OAUpstart interview questions
  • Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions
  • Time Needed to Rearrange a Binary StringSalesforce · OASalesforce interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Cheating CodemakerJane Street · OAJane Street interview questions
  • Count Subsequences Without Three Equal-Parity Elements in a RowGoogle · OAGoogle interview questions

Optiver interview experiences

  • Optiver SWE Intern OA: CPU Temperature Simulation: 1 Experience
  • Optiver Trading Intern Market-Making Games: 1 Experience
  • Optiver Quant Trader Intern Technical Interview: 1 Experience
  • Optiver SWE Intern System Design Interview: 15 Experiences
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public long countTransactionSequences(int startShares, int targetShares, int maxTransactions) {
        // write your code here
    }
}
Checking account…