Count Ordered Size Sequences
Updated
Problem statement
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[]) → longExamples
Example 1
n = 3sizes = [1,2]return = 3The valid ordered sequences are [1,1,1], [1,2], and [2,1].
Example 2
n = 4sizes = [1,3]return = 3The sequences are [1,1,1,1], [1,3], and [3,1].
Constraints
1 <= n <= 601 <= sizes.length <= 601 <= sizes[i] <= n- All values in
sizesare 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