Company: Rippling
Difficulty: medium
Dual Cache Performance Analysis A platform engineer is benchmarking two edge caches that sit in front of an incoming request queue. There are n requests waiting to be handled, and the payload size of the i th request is given by payloadSize[i]. Two caches, A and B, may each be able to serve the response to a given request. cacheA[i] = 1 means cache A is able to serve the i th request, otherwise it is 0, for all 1 ≤ i ≤ n cacheB[i] = 1 means cache B is able to serve the i th request, otherwise it is 0, for all 1 ≤ i ≤ n Determine the smallest possible total payload size of a chosen group of requests such that cache A alone can cover at least minThreshold of the chosen requests and cache B alone can also cover at least minThreshold of them, or report -1 if no such group exists. Constraints 1 ≤ n ≤ 2 * 10 5 1 ≤ payloadSize[i] ≤ 10 9 0 ≤ cacheA[i], cacheB[i] ≤ 1 1 ≤ minThreshold ≤ n Input Format For Custom Testing The first line contains an integer n, the number of requests. The next n lin