FastPrepMaximize Number of Produced Cars
Problems/Maximize Number of Produced Cars

Maximize Number of Produced Cars

Microsoft logoMicrosoft● MediumOA

Updated Sep 2026

QuestionFunctionExamples

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 interview questions

  • 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
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · 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
  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions

Microsoft interview experiences

  • 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)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int maximizeNumberOfProducedCars(int[] H, int X, int Y) {
      // write your code here
    }

}
Checking account…