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?
Write 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.
H = [1, 1, 3] X = 1 Y = 1 return = 2
H = [6, 5, 5, 4, 3] X = 8 Y = 9 return = 4
H = [6, 5, 2, 1, 8] X = 17 Y = 5 return = 5
H = [5, 5, 4, 6] X = 8 Y = 8 return = 2
- 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].
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Get Minimum TimeSeen Jun 2025
- Count Subarrays with Bitwise OR PresentSeen Jun 2025
- Get Max Or SumSeen Jun 2025
public int maxNumOfProducedCars(int[] H, int X, int Y) {
// write your code here
}