Description
Solutions
Choosing a Fleet of Vehicles
🔥 FULLTIME

Given an integer denoting a total number of wheels, find the number of different ways to choose a fleet of vehicles from an infinite supply of two-wheeled and four-wheeled vehicles such that the group of chosen vehicles has that exact total number of wheels. Two ways of choosing vehicles are considered to be different if and only if they contain different numbers of two-wheeled or four-wheeled vehicles.

For example, if our array wheels = [4,5,6] our return array would be res = [2, 0, 2]. Case by case, we can have 1 four-wheel or 2 two-wheel to have 4 wheels. We cannot have 5 wheels. We can have 1 four-wheel and 1 two-wheel or 3 two-wheel vehicles in the final case.

Function Description

Complete the function chooseFleets in the editor below. The function should return an array of integers representing the answer for each wheels[i].

chooseFleets has the following parameter(s):

  1. wheels[wheels[0],...wheels[n-1]]: an array of integers

Example 1:

Input:  wheels = [6, 3, 2]
Output: [2, 0, 1]
Explanation:
We mus find the number of ways of choosing fleets of vehicles whose total numbers of wheels correspond to the values in wheels = [6, 3, 2]: - For wheel0 = 6, we can choose a fleet with 6 total wheels into 2 ways: 1. Choose 1 four-wheeled vehicle and 1 two-wheeled vehicle. 2. Choose 3 two-wheeled vehicles. - There is no way to choose a fleet of vehicles with exactly wheels1 = 3 total wheels becasue each vehicle has either 2 or 4 wheels, so we store 0 in index 1 of our return array. - For wheels2 = 2, we can only choose 1 two-wheeled vehicle to get a fleet with 2 total wheels. Thus, we store 1 in index 2 of our retur narray.
Constraints:
  • 1 ≤ n ≤ 105
  • 1 ≤ wheels[i] ≤ 106
Thumbnail 0
Testcase

Result
Case 1

input:

output: