Minimum-Cost Color Sequence
Updated
Problem statement
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[][]) → StringExamples
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.
Example 3
costs = [[1,3,4],[1,5,6],[1,7,4]]return = "bgb"The unique valid minimum-cost sequence is bgb, with total cost 7.
Example 4
costs = [[18,13,12],[12,15,16],[1,7,4],[9,9,8]]return = "rgbr"The unique valid minimum-cost sequence is rgbr, with total cost 36.
Example 5
costs = [[100,22,99],[1,20,99],[76,1,5],[14,2,12]]return = "gbrg"The unique valid minimum-cost sequence is gbrg, with total cost 30.
Constraints
1 <= costs.length <= 100000.costs[i].length == 3.1 <= costs[i][j] <= 1000000.- The minimum-cost valid sequence is unique.
More OpenAI Online Assessment questions
- Count Routes Through Four Shop TypesOA · Seen Oct 2026
- Digit-Sum Sequence Join PointOA · Seen Oct 2026
- Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
- Password Clues and the Next CommandOA · Seen Oct 2026
- Longest Increasing Price SubsequenceOA · Seen Oct 2026
- Macaron Order PriceOA · Seen Oct 2026
- Shortest Atom Action PathOA · Seen Oct 2026
- Simplify a Quadratic ExpressionOA · Seen Oct 2026
- Largest Microorganism After ConsumptionOA · Seen Oct 2026
- Invert or Blur an ImageOA · Seen Sep 2026
Similar questions at other companies
- Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
- Jump GamePaytm · PHONE SCREENPaytm interview questions
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- House RobberVisa · PHONE SCREENVisa interview questions