Maximize Number of Produced Cars
Updated
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
maxNumOfProducedCars(H: int[], X: int, Y: int) → intWrite a function:
class Solution { public int solution(int[] H, int X, int 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 = 2Only cars whose assembly time requires 1 hour can be constructed.
Example 2
H = [6, 5, 5, 4, 3]X = 8Y = 9return = 4The 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 = 5The 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 = 2Only one car can be produced on each line.
Constraints
- N is an integer within the range [1..1,000];
- each element of array H is an integer within the range [1..1,000];
- X and Y are integers within the range [1..500].
More Microsoft interview questions
- Maximum Score with Prime JumpsOA · Seen Dec 2026
- Minimum Non-Adjacent Selection CapabilityOA · Seen Dec 2026
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Authentication SystemOA · Seen Nov 2026
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Aggressive CowsPeopleStrong · OAPeopleStrong interview questions
- Spread Cows Across StallsExpedia · OAExpedia interview questions
- Aggressive CowsAmazon · PHONE SCREEN
- Maximize the Minimum Cone DistanceSumo Logic · PHONE SCREEN
- Maximize Fish over Limited HoursByteDance · PHONE SCREENByteDance interview questions
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)