FastPrepEconomical Trip

Economical Trip

Accenture logoAccenture● EasyFULLTIMEOA
Learn

Problem statement

A company has n teams. The integer array teamSizes gives the number of members in each team, and carSeats[i] gives the number of seats in the one car owned by team i.

A team participates in the company trip only when it has more than two members. If a team does not participate, neither its members nor its car are used. Members of participating teams may share cars across team boundaries.

Return the minimum number of participating teams' cars needed to carry every participating member. Return -1 if no team participates or if the available participating cars cannot carry everyone.

Function

minimumCars(n: int, teamSizes: int[], carSeats: int[]) → int

Examples

Example 1

n = 3teamSizes = [4,5,7]carSeats = [7,6,7]return = 3

All three teams participate, so 16 members need seats. The two largest cars have only 14 seats together, so all three cars are required.

Example 2

n = 4teamSizes = [4,2,3,5]carSeats = [6,9,5,7]return = 2

The second team does not participate, so its 9-seat car is unavailable. The remaining teams have 12 members, and the 7- and 6-seat cars can carry them using two cars.

Example 3

n = 3teamSizes = [2,1,2]carSeats = [5,4,6]return = -1

No team has more than two members, so nobody participates and the required result is -1.

Constraints

  • 1 <= n <= 10^5.
  • teamSizes.length == n.
  • carSeats.length == n.
  • 1 <= teamSizes[i] <= 10^9.
  • 1 <= carSeats[i] <= 10^9.

More Accenture problems

See Accenture hiring insights
public int minimumCars(int n, int[] teamSizes, int[] carSeats) {
    // Write your code here.
}
n3
teamSizes[4,5,7]
carSeats[7,6,7]
expected3
Checking account…