Work Schedule
Updated
Problem statement
An employee has to work exactly as many hours as they are told to each week, scheduling no more than a given daily maximum number of hours. On some days, the number of hours worked will be given. The employee gets to choose the remainder of their schedule, within the given limits.
A completed schedule consists of exactly 7 digits in the range 0 to 8 that represent each day's work hours. A pattern string similar to the schedule is given, but some of its digits are replaced by a question mark, ?, (ascii 63 decimal). Given a maximum number of hours that can be worked in a day, replace the question marks with digits so that the sum of the scheduled hours is exactly the hours that must be worked in a week.
Determine all possible work schedules that meet the requirements and return them as a list of strings, sorted ascending.
Function
findSchedules(work_hours: int, day_hours: int, pattern: String) → String[]
Complete the function findSchedules in the editor below.
findSchedules has the following parameter(s):
- 1.
int work_hours: the hours that must be worked in the week - 2.
int day_hours: the maximum hours that may be worked in a day - 3.
String pattern: the partially completed schedule
Returns
String[]: represents all possible valid schedules (must be ordered lexicographically ascending)
Examples
Example 1
work_hours = 24day_hours = 4pattern = "08??840"return = ["0804840", "0813840", "0822840", "0831840", "0840840"]There are two days on which they must work 24 - 20 = 4 more hours for the week. All of the possible schedules are listed below:
- 0804840
- 0813840
- 0822840
- 0831840
- 0840840
Constraints
- 1 ≤ work_hours ≤ 56
- 1 ≤ day_hours ≤ 8
- | pattern | = 7
- Each character of pattern ∈ {0, 1,...,8}
- There is at least one correct schedule.
More Snowflake interview questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
- Safest Shortest Path Through a GridOA · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Work Schedules (for MTS2)Nutanix · OANutanix interview questions
- DFS Subsequences of a String (For MLE)Wayfair · OAWayfair interview questions
- Next Number with Disjoint DigitsElevenLabs · OAElevenLabs interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Generate ParenthesesThe Walt Disney Company · OAThe Walt Disney Company interview questions
- Reverse and AppendUber · OAUber interview questions
- All Palindrome PartitionsExpedia · OAExpedia interview questions
- Generate ParenthesesAtlassian · OAAtlassian interview questions
- Equal-Sum Digit PartitionsAlchemy · OA
- Maximum Number after K SwapsIntuit · OAIntuit interview questions