Problem statement
Write function solution(rules, requests). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. rules:{effect,subject,action,resource}[]; requests:{subject,action,resource}[]. A rule matches when each field is '*' or an exact case-sensitive match. Any matching 'deny' overrides every allow. Otherwise allow if a matching 'allow' exists, deny by default. Ignore other effects. Rule order does not matter. Return booleans in request order. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
{
"effect": "allow",
"subject": "alice",
"action": "*",
"resource": "*"
}
],
[
{
"subject": "alice",
"action": "read",
"resource": "file"
},
{
"subject": "bob",
"action": "read",
"resource": "file"
}
]
]Return value
[ true, false ]
Example 2
Function arguments
[
[
{
"effect": "allow",
"subject": "*",
"action": "*",
"resource": "*"
},
{
"effect": "deny",
"subject": "alice",
"action": "*",
"resource": "*"
}
],
[
{
"subject": "alice",
"action": "read",
"resource": "file"
},
{
"subject": "bob",
"action": "read",
"resource": "file"
}
]
]Return value
[ false, true ]
Example 3
Function arguments
[
[
{
"effect": "deny",
"subject": "bob",
"action": "*",
"resource": "*"
},
{
"effect": "allow",
"subject": "*",
"action": "*",
"resource": "*"
}
],
[
{
"subject": "alice",
"action": "read",
"resource": "file"
}
]
]Return value
[ true ]