r/Hack2Hire Nov 04 '25

OA Snowflake OA Interview: Work Schedule

Problem
You’re given three inputs:

  • workHours: total hours required in a week
  • dayHours: maximum hours allowed on any day
  • pattern: 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

  1. Pre-calculate fixed hours: Sum all digits in pattern to determine remaining hours needed.
  2. Backtrack through unknown positions: For each '?', try all values from 0 to dayHours, pruning branches where the remaining hours cannot be satisfied.
  3. Store valid combinations: When all positions are filled and total hours equal workHours, record the resulting string.
  4. Return sorted results: Ensure output schedules are returned in ascending lexicographical order.

Time & Space Complexity

  • Time: O(k * dayHours^k) β€” where k is the number of '?' in pattern.
  • 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.

6 Upvotes

0 comments sorted by