Maximize Workday Earnings
Reported by candidates from Citadel's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Citadel OA reported in September 2026 looks like a simple scheduling problem, but one edge case wrecks the obvious approach. You get a string of W and O days, flip at most k off days to workdays, and maximize pay with a bonus for adjacent workdays. It's a greedy problem on gap lengths. If you blank on the setup, StealthCoder runs invisibly during the live assessment and can hand you the structure. Read this first so you don't need it.
The problem
You are given a work schedule schedule. Each character is W for a workday or O for a day off. Every workday earns dailyPay. A workday also earns consecutiveBonus when the immediately preceding day is a workday. You may change at most k occurrences of O into W. Return the maximum total earnings after the changes. Both pay values are nonnegative, so changing an additional available day off can never reduce the result. Function maximizeEarnings(schedule: String, k: int, dailyPay: long, consecutiveBonus: long) → long Examples Example 1 schedule = "WOWO" k = 1 dailyPay = 10 consecutiveBonus = 5 return = 40 Changing the middle day off produces WWWO. Three workdays earn 30, and the two adjacent workday pairs earn 10 in bonuses. Example 2 schedule = "OOOO" k = 2 dailyPay = 10 consecutiveBonus = 5 return = 25 Choose two adjacent days. The two workdays earn 20, and their one adjacency earns a bonus of 5. Example 3 schedule = "WWOOOW" k = 2 dailyPay = 10 consecutiveBonus = 5 return = 65 Use both changes next to the leading run, producing four consecutive workdays and one separated workday. Five workdays earn 50, and three adjacencies earn 15. Constraints 1 <= schedule.length <= 200000 schedule[i] is W or O. 0 <= k <= schedule.length 0 <= dailyPay, consecutiveBonus <= 10^9 The answer fits in a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Every flipped day earns dailyPay, so you always use all k flips (or run out of O days). The real value is in adjacency bonuses. Total earnings equal dailyPay times workdays plus bonus times adjacent W-W pairs. Flipping an O gives dailyPay plus a bonus for each W neighbor. Filling an entire gap between two W runs earns the most: the last flip in that gap adds two bonuses. So split O runs into interior gaps (W on both sides), edge gaps (W on one side), and the all-O case. Sort interior gaps by length ascending and fill the smallest completely first. Then spend leftover flips on edge gaps, where each flip adds one bonus. Then any remaining flips start new runs. The pitfall is the all-O string, where the first flip earns no bonus. Another is k exceeding the O count. Use 64-bit math. If this logic slips under pressure, StealthCoder is the hedge on the live OA.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Maximize Workday Earnings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Citadel's OA.
Citadel reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximize Workday Earnings FAQ
What's the trick in Maximize Workday Earnings?+
Count adjacency, not just workdays. Closing a whole interior gap between two W runs gives the final flip two bonuses instead of one. So you sort interior gaps by length ascending and fill the shortest ones completely first.
What edge case breaks the naive solution?+
An all-O schedule. There's no existing W to attach to, so the first flip earns only dailyPay and no bonus. Example 2 shows it: two flips give 20 plus one bonus of 5. Also watch k larger than the number of O days.
Is a plain left-to-right greedy enough?+
No. Flipping the first available O each time ignores gap sizes and misses the double-bonus from closing gaps. You need to classify gaps as interior, edge, or none, then allocate flips by value.
What complexity should I aim for?+
Sorting the interior gaps gives O(n log n), which is fine for a length of 200000. A single pass builds the gap list. Use long arithmetic since pay values reach 10^9 and totals get large.
How do I prepare for this in 48 hours?+
Hand-trace the three examples, then write the gap classification and sort. Test an all-O string, k equal to 0, and k bigger than the O count. Those three cases catch most wrong answers on this problem.