Fill a weekly work schedule to an exact hour total
I was asked this
No reports yet. Sign in to say where you were asked it.
A week's work plan is written as a 7-character string pattern, one character per day. A digit (0-9) is a day whose hours are already set. A ? is a day that is still open.
Implement:
def find_schedules(work_hours: int, day_hours: int, pattern: str) -> list[str]
Replace every ? with a digit from 0 to day_hours so that the seven digits sum to exactly work_hours. Return every valid schedule as a 7-character string, in ascending lexicographic order. Return an empty list if none exists. Digits already in the pattern never change.
Constraints
len(pattern) == 70 <= day_hours <= 80 <= work_hours <= 56
Example 1
work_hours = 24, day_hours = 4, pattern = "08??840"
-> ["0804840", "0813840", "0822840", "0831840", "0840840"]
The fixed days sum to 20, so the two open days must share 4 hours, each at most 4.
Example 2
work_hours = 10, day_hours = 3, pattern = "1111111"
-> []
There are no open days and the fixed days sum to 7, not 10.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
