← Questions

Fill a weekly work schedule to an exact hour total

0
SnowflakeCoding

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) == 7
  • 0 <= day_hours <= 8
  • 0 <= 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.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding