← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design a workspace usage quota enforcer that tracks resource consumption against per-resource limits. Implement a class QuotaEnforcer with the following API:
setQuota(resource: str, limit: int) -> None – sets or updates the maximum allowed usage for the named resource. A limit of 0 means the resource is blocked. If the resource was not previously tracked, it is added; if it was, its limit is updated.recordUsage(resource: str, amount: int) -> bool – attempts to consume amount units of the resource. If the resource has a quota and the request would exceed the quota, return False and leave usage unchanged. Otherwise increment the usage counter by amount and return True. If the resource has no quota, always return True and still increment usage.getRemaining(resource: str) -> int – returns the number of units still available for the resource. If the resource has no quota, return –1. If the resource has a quota but has not been used, return the full quota.resetUsage(resource: str) -> None – resets the consumed usage for the resource to 0, without changing its quota.All operations must be atomic with respect to the internal state. The system must handle limits and usage values up to 1 000 000 000.