FastPrepFastPrep
Problem Brief

Count Ways to Select Fleet

OA
See Amazon online assessment and hiring insights

You are given an integer representing a total count of wheels. Your task is to determine how many distinct ways you can form a group of vehicles using an unlimited supply of two-wheeled and four-wheeled types such that the sum of their wheels equals the given total.

Two arrangements are considered unique if the count of two-wheeled or four-wheeled vehicles used differs between them.

The function should return a list of integers, where each value corresponds to the number of valid combinations for the respective total in the input list.

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ wheels[i] ≤ 10^9

1Example 1

Input
wheels = [6, 3, 2]
Output
[2, 0, 1]
Explanation
For a total of 6 wheels: Option 1: One four-wheeled vehicle + one two-wheeled vehicle Option 2: Three two-wheeled vehicles Total combinations = 2 πŸ¦” 🦍 πŸ’ 🐒 🐘 πŸ¦’ πŸͺ 🦭 🦀 πŸͺΏ 🦩 🦧 For 3 wheels: No possible arrangement can sum to 3 wheels using only 2- and 4-wheeled vehicles Total combinations = 0 πŸ“ πŸ‰ 🍊 πŸ‹ πŸ₯‘ πŸ₯ πŸ₯­ πŸ… πŸ‹β€πŸŸ© πŸ‡ πŸ₯₯ πŸ‘ For 2 wheels: Only possible using one two-wheeler Total combinations = 1

2Example 2

Input
wheels = [4, 5, 6]
Output
[2, 0, 2]
Explanation
For 4 wheels: either 1 four-wheeler or 2 two-wheelers. For 5 wheels: it is impossible. For 6 wheels: either 1 four-wheeler + 1 two-wheeler or 3 two-wheelers.
public int[] countWaysToSelectFleet(int[] wheels) {
  // write your code here
}
Input

wheels

[6, 3, 2]

Output

[2, 0, 1]

Sign in to submit your solution.