Minimum Cost with Adjacent Choices Different
Updated
Problem statement
You are given a rectangular cost matrix costs. Choose exactly one column in each row and pay the cost at that position. Consecutive rows must choose different columns; nonconsecutive rows may reuse a column.
For this exercise, assume the matrix represents a sequence of items with the same available choices in every row. Return the minimum total cost satisfying the adjacent-choice rule. Return 0 for no rows and -1 when no valid sequence exists.
Function
minAdjacentChoiceCost(costs: int[][]) → intExamples
Example 1
costs = [[1,7],[4,2],[3,8]]return = 6Choose columns 0, 1 and 0, paying 1 + 2 + 3. Reusing column 0 after a gap is allowed.
Example 2
costs = [[3],[5]]return = -1Only one column is available, so two consecutive rows cannot choose different columns.
Example 3
costs = []return = 0There are no rows and no cost to pay.
Constraints
0 <= costs.length <= 80.- For nonempty input, every row has the same length
k, with1 <= k <= 16. 0 <= costs[r][c] <= 10^6.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Card Game: Best First-Player ScoreShopify · OAShopify interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Maximum Subarray SumStraive · OA
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
- Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
- API Bandwidth AllocationArista Networks · OAArista Networks interview questions