Minimum-Cost Color Sequence
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this OpenAI question, reported in September 2026, is going greedy. You pick the cheapest color each day, skip yesterday's color, and it looks right until a cheap pick today forces an expensive one tomorrow. This is the paint-house problem with a twist: you have to return the actual color string, not just the cost. That means tracking choices, not only totals. If you have the OA in the next day or two, learn the three-state DP and the backtrack step. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment.
The problem
For each day i, costs[i][0], costs[i][1], and costs[i][2] are the costs of choosing blue, green, or red. Choose exactly one color per day, and never choose the same color on consecutive days. Return the unique minimum-cost color sequence as a string using b, g, and r. Function minimumCostColorSequence(costs: int[][]) → String Examples Example 1 costs = [[1,5,9],[4,2,8],[7,6,1]] return = "bgr" Choosing blue, green, then red costs 1 + 2 + 1 = 4, which is the unique minimum. Example 2 costs = [[7,2,5]] return = "g" With one day, the least expensive choice is green. Constraints 1 <= costs.length <= 100000. costs[i].length == 3. 1 <= costs[i][j] <= 1000000. The minimum-cost valid sequence is unique.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is dynamic programming with three states per day. Let dp[i][c] be the minimum cost to finish day i ending on color c. Then dp[i][c] = costs[i][c] + min(dp[i-1][other two colors]). You only need the previous row, so space is O(1) for cost. But you must return the sequence, so store a parent pointer per day and color, which is O(n) memory with n up to 100000. Pick the best final color, then walk the parents backward and reverse. The common pitfall is greedy, and the second is forgetting to map indices correctly: 0 is b, 1 is g, 2 is r. Skip recursion here, since depth 100000 will blow the stack. The uniqueness guarantee means no tie-break logic is needed. If you freeze on the reconstruction, StealthCoder is the hedge during 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 Minimum-Cost Color Sequence 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 OpenAI's OA.
OpenAI 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.
Minimum-Cost Color Sequence FAQ
What's the trick in the Minimum-Cost Color Sequence problem?+
Run a DP over days with three states, one per color. Each state's cost is today's cost plus the minimum of yesterday's other two colors. Greedy fails because a cheap pick now can force a costly one later. Keep parent pointers so you can rebuild the string.
How do I return the sequence and not just the cost?+
Store, for each day and color, which previous color gave the minimum. After the last day, choose the color with the lowest total. Then follow the parent pointers back to day 0, collect letters, and reverse them. Map 0 to b, 1 to g, 2 to r.
Why does greedy fail here?+
Picking the cheapest color each day ignores the constraint's ripple effect. Taking a 1 today might block a 1 tomorrow and force a 1000000 instead. Example 1 happens to work with greedy, so don't trust it. DP compares all valid paths without enumerating them.
Can I use recursion with memoization?+
You can, but with up to 100000 days the recursion depth will likely overflow the stack in many languages. A bottom-up loop is safer and simpler. It also makes the parent-pointer reconstruction easy since you fill rows in order.
How do I prepare for this in 48 hours?+
Code the paint-house DP from scratch twice, once cost-only and once with reconstruction. Test the single-day case from Example 2. Check that your costs use 64-bit-safe types, since totals can reach 100000 times 1000000. That covers what this question tests.