Problem Β· Math

Count Ways to Select Fleet

● EasyAmazonOA
See Amazon 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

Examples
01 Β· Example 1
wheels = [6, 3, 2]
return = [2, 0, 1]
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
02 Β· Example 2
wheels = [4, 5, 6]
return = [2, 0, 2]
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.
More Amazon problems
drafts saved locally
public int[] countWaysToSelectFleet(int[] wheels) {
  // write your code here
}
wheels[6, 3, 2]
expected[2, 0, 1]
sign in to submit