Uber OA-10 2023
Problem Description
You are given a sorted array of vehicle types ( v ), where each element indicates the number of passengers that a vehicle can accommodate. Each vehicle type has an infinite supply. You also have a total number of passengers ( p ).
Your task is to determine the minimum number of vehicles needed to accommodate all passengers without leaving any seats empty. If it's not possible to accommodate all passengers without wasting seats, return the minimum number of vehicles required while minimizing seat wastage.
Input Format:
- A sorted array
v
of integers where each element represents the number of people a vehicle can accommodate. - An integer
p
, representing the total number of passengers.
Output Format:
- An integer representing the minimum number of vehicles required to accommodate all passengers without wasting any seats. If it's impossible to accommodate passengers without seat wastage, return the minimal number of vehicles with seat wastage.
Constraints:
- 1<=v[i]<=100
- 0 <= p<=1000
- 1 <= n <=100
Sample Testcase 1:
Input:
v = [1, 3, 4, 5], p = 4
Output:
1
Explanation:
Given the availability of vehicles with seat capacities [1, 3, 4, 5]
, the most efficient way to accommodate 4 passengers is to use a single vehicle with 4 seats. This ensures that there is no wastage of seats.