Count Shipment Schedules
Updated
Problem statement
A binary string stock represents a shipment schedule. A 1 marks a day with a shipment already scheduled, and a 0 marks an empty day.
Choose exactly k different empty days and change their zeros to ones. Count the different resulting schedules. Do not change any other position.
Return the exact count, without a modulus. If fewer than k empty days exist, return 0. Choosing zero days gives one schedule: the original string.
For this exercise, assume an empty schedule is allowed. It has one result when k = 0 and no results otherwise. The number of days is stock.length.
Function
countShipmentSchedules(stock: String, k: int) → longExamples
Example 1
stock = "1010100"k = 3return = 4The seven-day schedule has four empty days, at zero-based positions 1, 3, 5, 6. Choose any three. The four possible sets are {1,3,5}, {1,3,6}, {1,5,6}, and {3,5,6}.
Example 2
stock = "010"k = 1return = 2Choose position 0 to get 110, or position 2 to get 011. These are the only two choices.
Constraints
- For this exercise, assume 0 <= stock.length <= 60.
- stock contains only '0' and '1'.
- For this exercise, assume 0 <= k <= 60.
- The exact count fits a signed 64-bit integer.
More Morgan Stanley Online Assessment questions
- Three-Resource 0/1 KnapsackOA · Seen Sep 2026
- Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
- Maximum Total of Nonadjacent RatingsOA · Seen Jul 2026
- Delete and EarnOA · Seen Apr 2026
- Interleave Array HalvesOA · Seen Apr 2026
- Get Patch SequenceOA · Seen Feb 2025
- String Subsequences 🐳OA · Seen Mar 2024
- Binary Tree Level OrderOA · Seen Feb 2024
- Merge IntervalsOA · Seen Feb 2024
- Format Chemical SymbolsOA · Seen Feb 2023
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Find Encrypted NumberAmazon · OA
- Valid PasswordsMathWorks · OAMathWorks interview questions
- Coloring HousesSnowflake · OASnowflake interview questions
- Find Maximum Number of StringsMoveworks · OAMoveworks interview questions
- Count Distinct Binary Search TreesC3.ai · OAC3.ai interview questions
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Stable Workload Redistribution TreesTower Research Capital · OA
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
Interview reports that mention this question
Morgan Stanley interview experiences
- Morgan Stanley New Grad Technology Analyst: 2 Experiences
- Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)
- Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
- Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
- Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)