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.deviceCapacity = 7 foregroundAppList = [[1, 2], [2, 4], [3, 6]] backgroundAppList = [[1, 2]] return = [[2, 1]]
deviceCapacity = 10 foregroundAppList = [[1, 3], [2, 5], [3, 7], [4, 10]] backgroundAppList = [[1, 2], [2, 3], [3, 4], [4, 5]] return = [[2, 4], [3, 2]]
deviceCapacity = 16 foregroundAppList = [[2, 7], [3, 14]] backgroundAppList = [[2, 10], [3, 14]] return = [[]]
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int[][] optimalUtilization(int deviceCapacity, int[][]foregroundAppList, int[][] backgroundAppList) {
// write your code here
}