This is a verified interview question from Uidai. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Throttle Shields" covers key patterns like Other.
"You operate a small "shield" in front of a busy API. Requests arrive at integer seconds. You can keep at most B requests waiting in a buffer. When the buffer is full and new requests arrive, the newest arrivals beyond capacity must be dropped. The API enforces two rolling send limits at the same time: across any W1-second window, at most M1 sends are allowed; across any W2-second window, at most M2 sends are allowed. At each second you may send any number of buffered requests as long as both rolling limits are respected. Send from the front of the buffer (FIFO). If the buffer overflows at a second, discard the newest arrivals at that second until the buffer size becomes B. Your goal is to minimize the number of dropped requests and report that minimum. ### Function Description Implement the function minDropped which takes the request timestamps and the two rolling limits plus buffer size, and returns the minimum number of dropped requests. ### Function Parameters - n: An int representing the number of requests. - w1: An int representing the first window length in seconds. - m1: An int representing the maximum sends allowed within any w1-second window. - w2: An int representing the second window length in seconds. - m2: An int representing the maximum sends allowed within any w2-second window. - b: An int representing the buffer capacity (maximum number of waiting requests). - t: An int[] representing the arrival times (in seconds) for all requests. ### Return An int — the minimal number of dropped requests following the rules."
Join thousands of developers practicing for Uidai.