Skip to main content

Uber

UBER OA 2023 - Sorted Array


Problem Description:
You are given a sorted array of vehicle types v, where each element represents the number of passengers a vehicle can accommodate. Each vehicle type has an infinite number of vehicles. Additionally, you are provided with the total number of passengers p. Your task is to determine the minimum number of vehicles required to accommodate all the passengers without wasting any seats. If it is not possible to accommodate all passengers without wasting seats, return the number of vehicles with minimal 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.