Extend a basic rate limiter so that each request contains multiple fields such as userId, deviceId, or endpoint.
Each field dimension has its own rule of the form fieldName window limit. For the same field value, allow at most limit requests inside a window of length window seconds.
A request is ALLOWed only if it stays within the limit for every configured dimension. If any one dimension exceeds its limit, the request is REJECTed.
Complete the function applyMultiFieldRateLimiter in the editor below.
applyMultiFieldRateLimiter has the following parameters:
String[] fieldRules: each entry has the form"fieldName window limit"String[] requests: each entry has the form"timestamp value1 value2 ..."in the same order as the field rules
Returns
String[]: one result per request, each being ALLOW or REJECT.
fieldRules = ["user 10 2", "device 10 3"] requests = ["1 u1 d1", "2 u1 d1", "3 u1 d1", "4 u2 d1", "11 u1 d1", "12 u1 d1"] return = ["ALLOW", "ALLOW", "REJECT", "ALLOW", "ALLOW", "ALLOW"]
The third request is rejected because the user dimension exceeds its limit even though the device dimension is still valid.
fieldRules = ["user 5 1", "endpoint 3 2"] requests = ["1 u1 /a", "2 u1 /a", "2 u2 /a", "4 u2 /a"] return = ["ALLOW", "REJECT", "ALLOW", "REJECT"]
The second request fails the user rule, while the fourth request fails the endpoint rule because that endpoint already hit its limit in the active window.
1 <= fieldRules.length <= 101 <= requests.length <= 2 * 10^5- Each field value contains no spaces.
- Timestamps are non-decreasing.
- Candy Crush Grid Matching and GravityPHONE SCREEN · Seen Jun 2026
- Closest Binary Search Tree Value VariantPHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Find the Closest PalindromePHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest PersonPHONE SCREEN · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026
- Meeting Rooms IIPHONE SCREEN · Seen Jun 2026
public String[] applyMultiFieldRateLimiter(String[] fieldRules, String[] requests) {
// write your code here
}