FastPrepCount Ordered Size Sequences
Problems/Count Ordered Size Sequences

Count Ordered Size Sequences

Optiver logoOptiver● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Optiver intern online assessment. The report gives the target, the rule that you can reuse sizes without limit, the goal of counting ordered sequences, and a worked example. It does not say how repeated sizes are handled, and it has no function signature or input limits. We added those. Our version is about 96% the same as the reported question.

Given a positive target n and an array of distinct positive integers sizes, count the ordered sequences of values from sizes whose sum is exactly n.

Each size may be used any number of times. Two sequences are different when they differ at any position, so order matters.

Return the number of valid sequences.

Function

countOrderedSums(n: int, sizes: int[]) → long

Examples

Example 1

n = 3sizes = [1,2]return = 3

The valid ordered sequences are [1,1,1], [1,2], and [2,1].

Example 2

n = 4sizes = [1,3]return = 3

The sequences are [1,1,1,1], [1,3], and [3,1].

Constraints

  • 1 <= n <= 60
  • 1 <= sizes.length <= 60
  • 1 <= sizes[i] <= n
  • All values in sizes are distinct.
  • 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 Bounded Share TransactionsOA · 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) · OA
  • Count Routes Through Four Shop TypesOpenAI · OA
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OA
  • Count Combinations Using Weights One Through KConfluent · OA
  • Count Strictly Increasing Subsequences of Length 3IBM · OA
  • Count Shipment SchedulesMorgan Stanley · OA
  • Replace '?' to Avoid Adjacent DuplicatesSalesforce · OA
  • Count Subsequences Without Three Equal-Parity Elements in a RowGoogle · OA
  • Binary Palindromic Subsequences of Length 5Citadel · OA
  • Count Equal-Frequency SubsequencesExpedia · OA
See Optiver hiring insights
Saved
class Solution {
    public long countOrderedSums(int n, int[] sizes) {
        // write your code here
    }
}
Checking account…