Enumerate Weekly Work Schedules
Updated
Problem statement
An employee must work an exact number of hours each week. On any one day they may work at most a given maximum number of hours. Some days already have their hours filled in. The employee picks the hours for the other days, within these limits.
A finished schedule is exactly 7 digits, each from 0 to 8. Each digit is the hours worked on one day. You get a pattern string shaped like a schedule, but the days still to be chosen are shown as a question mark, ? (ASCII 63 in decimal). Replace each question mark with a digit no larger than the daily maximum, so that all the hours add up to exactly the weekly total.
Find every schedule that meets these rules. Return them as a list of strings, sorted in ascending order.
Complete the function findSchedules in the editor. It gets these parameters:
- 1.
int work_hours: the total hours that must be worked in the week - 2.
int day_hours: the most hours that may be worked on one day - 3.
String pattern: the partly filled-in schedule
findSchedules returns String arr[]: every valid schedule, sorted in ascending dictionary (lexicographic) order.
Function
findSchedules(work_hours: int, day_hours: int, pattern: String) → String[]Examples
Example 1
work_hours = 24day_hours = 4pattern = "08??840"return = ["0804840", "0813840", "0822840", "0831840", "0840840"]There are 2 unknown days and 24 - 20 = 4 hours left to schedule. The five listed schedules use every split of 4 in which each day is between 0 and 4 hours.
Example 2
work_hours = 56day_hours = 8pattern = "???8???"return = ["8888888"]There is only one way to work 56 hours in 7 days when at most 8 hours may be worked each day.
Example 3
work_hours = 3day_hours = 2pattern = "??2??00"return = ["0020100", "0021000", "0120000", "1020000"]The fixed 2 hours leave 1 more hour to schedule, and it can be placed on any one of the four question-mark days.
Constraints
- 1 ≤ work_hours ≤ 56
- 1 ≤ day_hours ≤ 8
- pattern has exactly 7 characters
- Each character of pattern ∈ {0, 1, ..., 8}
- There is at least one correct schedule.
More Agoda Phone Screen questions
- Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Can Place FlowersPHONE SCREEN · Seen Nov 2026
- Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
- Disk Space Window AnalyzerPHONE SCREEN · Seen Sep 2026
- Shortest Subarray With the Full DegreePHONE SCREEN · Seen Sep 2026
- Count Values Appearing Exactly OncePHONE SCREEN · Seen Sep 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Sep 2026
- Chemical Formula WeightPHONE SCREEN · Seen Sep 2026
- Find the Pivot ElementPHONE SCREEN · Seen Sep 2026
- Maximum Planes Destroyed Before LandingPHONE SCREEN · Seen Jan 2026
Similar questions at other companies
- DFS Subsequences of a String (For MLE)CoinDCX · PHONE SCREEN
- Generate Wildcard Binary StringsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Phone-Number Letter CombinationsHeadway · PHONE SCREENHeadway interview questions
- Letter Combinations of a Phone NumberLinkedIn · PHONE SCREENLinkedIn interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Balanced Parentheses with Sequential Left DeletionsGoogle · PHONE SCREENGoogle interview questions
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Unique String PermutationsAmazon · PHONE SCREEN
- Expression Add OperatorsPinterest · PHONE SCREENPinterest interview questions