Problem · Array

Maximize Number of Produced Cars

Learn this problem
MediumMicrosoftOA
See Microsoft hiring insights

Problem statement

A car manufacturer has data about the production processes of N different cars (numbered from 0 to N-1) and wants to maximize the number of cars produced in the upcoming month. The manufacturing information is described by an array H, where H[K] denotes the number of hours required to produce the K-th car.

There are two assembly lines in the factory, the first of which works for X, and the second Y, hours in a month. Every car can be constructed using either one of these lines. Only one car at a time can be produced on each assembly line and it is not possible to switch lines after starting the car's production.

What is the maximum number of different cars that can be produced in the upcoming month?

Function

maximizeNumberOfProducedCars(H: int[], X: int, Y: int) → int

Write a function:

def solution(H, X, Y)

that, given an array H of N integers and two integers X and Y, returns the maximum number of different cars that can be produced in the upcoming month by assigning cars to assembly lines in an optimal way.

Examples

Example 1

H = [1, 1, 3]X = 1Y = 1return = 2
Only cars whose assembly time requires 1 hour can be constructed.

Example 2

H = [6, 5, 5, 4, 3]X = 8Y = 9return = 4
The cars that need 3 and 5 hours can be produced on the first assembly line while the second car that needs 5 hours and the car that needs 4 hours can be produced using the second line.

Example 3

H = [6, 5, 2, 1, 8]X = 17Y = 5return = 5
The car that needs 5 hours can be produced on the second line and the four other cars can be produced on the first line.

Example 4

H = [5, 5, 4, 6]X = 8Y = 8return = 2
Only one car can be produced on each line.

More Microsoft problems

drafts saved locally
public int maximizeNumberOfProducedCars(int[] H, int X, int Y) {
  // write your code here
}
H[1, 1, 3]
X1
Y1
expected2
checking account