Question: Amazon, Recent Online Assessment Questions | Amazon Logistics | Dividing Application into Clusters | 2023
1
Entering edit mode

ADD COMMENTlink 23 months ago PoGo 2.4k
0
Entering edit mode

Problem 1

Solution:
To form a fleet of vehicles using only two-wheeled and four-wheeled vehicles, we need to find the number of integer solutions to the equation:2a + 4b = W

Where:

  • a is the number of 2-wheeled vehicles

  • b is the number of 4-wheeled vehicles

This can be simplified as: a + 2b = W / 2

Let X = W / 2. We need to count all integer pairs (a, b) such that: a = X - 2b ≥ 0

This leads to:0 ≤ b ≤ X / 2

Which gives us: floor(X / 2) + 1 distinct combinations.

If W is odd, no valid solution exists.

Thus:

  • If W is odd → 0 combinations

  • If W is even → answer is (W / 4) + 1 (which is equivalent to floor((W / 2) / 2) + 1)

 

#include<bits/stdc++.h>

using namespace std;



int main(){
    int n ;
    cin >> n;
    vector<int> arr(n);

    for(int i =0  ;i <n;i++){
        cin >> arr[i];
    }
    vector<int> ans;
    for(int i = 0;i<n;i++){
        if (arr[i]%2 == 0){
            int a = arr[i]/4;
            ans.push_back(a+1);
        }else{
            ans.push_back(0);
        }
    }

    for(int i = 0;i<n;i++){
        cout << ans[i] << " ";
    }
    cout << endl;

}

Time Complexity

  • O(n) — processing each wheel count once.

Space Complexity

  • O(n) — storing results in an output array.

ADD COMMENTlink 19 days ago Suryansh Rishit • 0

Login before adding your answer.

APPLY NOWSimilar Posts
Loading Similar Posts