# Throttling Gateway
###### tags: `Array`, `Amazon OA`
Description:
Non-critical requests for a transaction system are routed through a throttling gateway to ensure that the network is not choked by request.
The gateway has the following limits:
* The number of transaction in any given second **cannot exceed 3**.
* The number of transaction in any given `10` seconds **cannot exceed 20**. A ten-second period includes all requests arriving from any time `max(1, T-9)` to `T`(Inclusive to both) for any valid time `T`.
* The number of transactions in any given minute **cannot exceed 60**. Similar to above, the period of `1` minute is from any time `max(1, T - 59)` to `T`.
Any request that exceeds any of above limits will be **dropped** by the gateway. Given the times at which different requests arrive sorted ascending, *find how many requests will be dropped*.
**Node**: Even if a request is dropped *it is still considered for future calculations*. Although, if a request is to be dropped due to multiple violations, it is still counted only once.
Input:
* `int n`: number of requests.
* `int[] requestsTime`: indecating how many requests in `ith` second.
**Example:**
```
n = 27
requestTime = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3,
4, 4, 4, 5, 5, 5, 6, 6, 6, 7,
7, 7, 7, 11, 11, 11, 11]
requestTime[3] : Dropped. Violate 3 second limit.
requestTime[21]: Dropped. Violate 10 second limit.
requestTime[22]: Dropped. Violate 10 second limit.
requestTime[23]: Dropped. Violate 3 second and 10 second limit.
requestTime[25]: Dropped. Violate 10 second limit.
requestTime[26]: Dropped. Violate 10 second limit.
requestTime[27]: Dropped. Violate 3 second and 10 second limit.
Total dropped: 7
```
Solution:
```java=
public int ThrottlingGateway(int n, int[] requestTime) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (i > 2 && requestTime[i] == requestTime[i - 3]) {
cnt++;
} else if (i > 19 && requestTime[i] - requestTime[i - 20] < 10) {
cnt++;
} else if (i > 59 && requestTime[i] - requestTime[i - 60] < 60) {
cnt++;
}
}
return cnt;
}
```