Car assembly game: pick one engine and four wheels to maximize survival score under a budget

Quick Overview

Choose exactly one engine and four wheels, with wheel types allowed to repeat, to maximize a car's total survival score without going over a budget. It tests knapsack dynamic programming with a fixed item count and combining the result with a prefix maximum for each engine choice.

Car assembly game: pick one engine and four wheels to maximize survival score under a budget

Company: Roblox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

You are assembling a car to survive an obstacle course with four obstacle types: water, bridges, missiles and acid. You have a `budget` and must choose parts that maximize the car's total survival score. You are given a list of `wheels` and a list of `engines`. Each part is represented as `[cost, water, bridge, missile, acid]`, where `cost` is the price and the remaining values are survival points against each obstacle type. You must select exactly 1 engine and exactly 4 wheels. Wheel slots are independent, so you may use the same wheel type more than once. The total cost of all selected parts must not exceed `budget`. Return the maximum total survival score achievable. If no valid configuration exists, return `0`. ### Function Signature ```python def max_survival_score(budget: int, wheels: list[list[int]], engines: list[list[int]]) -> int: ``` ### Rules - The survival score of one part is the sum of its four obstacle values, `water + bridge + missile + acid`. The cost is not part of the score. - The total survival score of a car is the sum of the survival scores of its 5 parts: 1 engine and 4 wheels. - A wheel type may fill any number of the 4 wheel slots. Exactly one engine is used. - A configuration is valid when the engine cost plus the costs of the 4 wheels is at most `budget`. - If no valid configuration exists, return `0`. ### Constraints - `1 <= budget <= 10000` - `1 <= len(wheels) <= 50` - `1 <= len(engines) <= 50` - `len(wheels[i]) == 5` and `len(engines[i]) == 5` - `1 <= cost <= 5000` - `0 <= survival points <= 100` ### Examples ```text Input: budget = 100, wheels = [[10,20,15,10,5],[15,25,20,15,10],[8,10,10,10,10]], engines = [[30,50,40,30,20],[50,70,60,50,40]] Output: 460 ``` The wheels score 50, 70 and 40 and cost 10, 15 and 8. The engines score 140 and 220 and cost 30 and 50. The engine that costs 50 leaves 50 for wheels, and two cost-15 wheels plus two cost-10 wheels spend exactly 50 for 70 + 70 + 50 + 50 = 240, so the total is 220 + 240 = 460. The cheaper engine leaves 70, where four cost-15 wheels give 280, for a total of only 420. ```text Input: budget = 50, wheels = [[10,5,5,5,5],[5,3,3,3,3]], engines = [[20,30,20,10,10],[10,15,10,5,5]] Output: 134 ``` The engine that costs 20 (score 70) leaves 30 for wheels, and two cost-10 wheels plus two cost-5 wheels spend exactly 30 for 20 + 20 + 12 + 12 = 64, giving 134. The engine that costs 10 (score 35) leaves 40, where four cost-10 wheels score 80, for a total of 115. ```text Input: budget = 10, wheels = [[3,10,10,10,10]], engines = [[1,5,5,5,5]] Output: 0 ``` Four wheels alone cost 12, which is already over the budget, so no valid car exists.

Overview: Choose exactly one engine and four wheels, with wheel types allowed to repeat, to maximize a car's total survival score without going over a budget. It tests knapsack dynamic programming with a fixed item count and combining the result with a prefix maximum for each engine choice.

Roblox logo
Roblox
Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

You are assembling a car to survive an obstacle course with four obstacle types: water, bridges, missiles and acid. You have a budget and must choose parts that maximize the car's total survival score.

You are given a list of wheels and a list of engines. Each part is represented as [cost, water, bridge, missile, acid], where cost is the price and the remaining values are survival points against each obstacle type.

You must select exactly 1 engine and exactly 4 wheels. Wheel slots are independent, so you may use the same wheel type more than once. The total cost of all selected parts must not exceed budget. Return the maximum total survival score achievable. If no valid configuration exists, return 0.

Function Signature

def max_survival_score(budget: int, wheels: list[list[int]], engines: list[list[int]]) -> int:

Rules

  • The survival score of one part is the sum of its four obstacle values, water + bridge + missile + acid . The cost is not part of the score.
  • The total survival score of a car is the sum of the survival scores of its 5 parts: 1 engine and 4 wheels.
  • A wheel type may fill any number of the 4 wheel slots. Exactly one engine is used.
  • A configuration is valid when the engine cost plus the costs of the 4 wheels is at most budget .
  • If no valid configuration exists, return 0 .

Constraints

  • 1 <= budget <= 10000
  • 1 <= len(wheels) <= 50
  • 1 <= len(engines) <= 50
  • len(wheels[i]) == 5 and len(engines[i]) == 5
  • 1 <= cost <= 5000
  • 0 <= survival points <= 100

Examples

Input: budget = 100, wheels = [[10,20,15,10,5],[15,25,20,15,10],[8,10,10,10,10]], engines = [[30,50,40,30,20],[50,70,60,50,40]]
Output: 460

The wheels score 50, 70 and 40 and cost 10, 15 and 8. The engines score 140 and 220 and cost 30 and 50. The engine that costs 50 leaves 50 for wheels, and two cost-15 wheels plus two cost-10 wheels spend exactly 50 for 70 + 70 + 50 + 50 = 240, so the total is 220 + 240 = 460. The cheaper engine leaves 70, where four cost-15 wheels give 280, for a total of only 420.

Input: budget = 50, wheels = [[10,5,5,5,5],[5,3,3,3,3]], engines = [[20,30,20,10,10],[10,15,10,5,5]]
Output: 134

The engine that costs 20 (score 70) leaves 30 for wheels, and two cost-10 wheels plus two cost-5 wheels spend exactly 30 for 20 + 20 + 12 + 12 = 64, giving 134. The engine that costs 10 (score 35) leaves 40, where four cost-10 wheels score 80, for a total of 115.

Input: budget = 10, wheels = [[3,10,10,10,10]], engines = [[1,5,5,5,5]]
Output: 0

Four wheels alone cost 12, which is already over the budget, so no valid car exists.