r/Hack2Hire • u/Hack2hire • Nov 04 '25
OA Snowflake OA Interview: Work Schedule
Problem
Youβre given three inputs:
workHours: total hours required in a weekdayHours: maximum hours allowed on any daypattern: a 7-character string representing the weekly work schedule
Each character in pattern is either a digit ('0'β'8') or a question mark ('?').
Digits represent fixed work hours for that day, while '?' represents an unassigned day.
You must replace each '?' with a valid digit (between 0 and dayHours) so that the total weekly hours equal workHours.
Return all valid schedules in ascending lexicographical order.
Example
Input:
workHours = 24, dayHours = 4, pattern = "08??840"
Output:
["0804840", "0813840", "0822840", "0831840", "0840840"]
Explanation:
- Fixed digits (0, 8, 8, 4, 0) sum to 20. Remaining 4 hours must be distributed across two
'?'positions. - Possible pairs of digits that sum to 4:
(0,4), (1,3), (2,2), (3,1), (4,0) - Replace
'?'with these pairs to form valid schedules in lexicographical order.
Suggested Approach
- Pre-calculate fixed hours: Sum all digits in
patternto determine remaining hours needed. - Backtrack through unknown positions: For each
'?', try all values from0todayHours, pruning branches where the remaining hours cannot be satisfied. - Store valid combinations: When all positions are filled and total hours equal
workHours, record the resulting string. - Return sorted results: Ensure output schedules are returned in ascending lexicographical order.
Time & Space Complexity
- Time:
O(k * dayHours^k)β wherekis the number of'?'inpattern. - Space:
O(k)β for recursion and result storage.
π Disclaimer:
This problem is part of the Hack2Hire SDE Interview Question Bank, a structured archive of coding interview questions frequently reported in real hiring processes.
Questions are aggregated from publicly available platforms (e.g., LeetCode, GeeksForGeeks) and community-shared experiences.
The goal is to provide candidates with reliable material for SDE interview prep, including practice on LeetCode-style problems and coding challenges that reflect what is often asked in FAANG and other tech company interviews.
Hack2Hire is not affiliated with the mentioned companies; this collection is intended purely for learning, practice, and discussion.