Optimal Utilization
Learn this problemProblem statement
You are given a device with a limited amount of memory. Each device must run two applications at the same time: one foreground application and one background application. Each application is identified by a unique integer ID (unique within its type), requires a fixed non-zero amount of memory to execute, and is classified as either foreground or background.
A pair of applications (one foreground and one background) is considered optimal if:
Your task is to write an algorithm that finds all pairs of foreground and background applications that optimally utilize the device memory.
The function should return a list of pairs [foregroundAppID, backgroundAppID] representing the IDs of applications that optimally utilize the device. If no valid pair exists, return a list with an empty pair.
Input Format
deviceCapacity representing the device's memory.Output Format
[foregroundAppID, backgroundAppID] for each optimal application pair.Function
optimalUtilization(deviceCapacity: int, foregroundAppList: int[][], backgroundAppList: int[][]) → int[][]Examples
Example 1
deviceCapacity = 7foregroundAppList = [[1, 2], [2, 4], [3, 6]]backgroundAppList = [[1, 2]]return = [[2, 1]]Example 2
deviceCapacity = 10foregroundAppList = [[1, 3], [2, 5], [3, 7], [4, 10]]backgroundAppList = [[1, 2], [2, 3], [3, 4], [4, 5]]return = [[2, 4], [3, 2]]Example 3
deviceCapacity = 16foregroundAppList = [[2, 7], [3, 14]]backgroundAppList = [[2, 10], [3, 14]]return = [[]]More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026