Problem · Design

Employee Resource Access Management

Learn this problem
MediumRipplingONSITE INTERVIEW

Problem statement

Implement an access-control service for employees and resources. One employee may hold several independent access types on the same resource.

Operations

Process rows in order and return one row for every operation.

  • ["GRANT", employeeId, resourceId, accessType]: Grant READ, WRITE, or ADMIN. Return ["true"] if a new grant was added and ["false"] if it already existed.
  • ["REVOKE", employeeId, resourceId, accessType]: Revoke one access type. Use ALL to revoke every access type the employee has on that resource. Return whether at least one grant was removed.
  • ["GET_ACCESS", employeeId, resourceId]: Return all access types currently held on that resource, sorted as READ, WRITE, ADMIN. Return an empty row when none exist.
  • ["GET_RESOURCES", employeeId]: Return every resource on which the employee currently has any access, sorted lexicographically. Return an empty row when none exist.

Interviewer follow-ups

Interviewers asked candidates to preserve multiple independent grants, make revocation precise, and discuss how the data model and APIs would evolve for larger access systems.

Function

manageEmployeeAccess(operations: String[][]) → String[][]

Examples

Example 1

operations = [["GRANT","e1","repo","READ"],["GRANT","e1","repo","WRITE"],["GRANT","e1","db","ADMIN"],["GET_ACCESS","e1","repo"],["GET_RESOURCES","e1"],["REVOKE","e1","repo","READ"],["GET_ACCESS","e1","repo"],["REVOKE","e1","repo","ALL"],["GET_RESOURCES","e1"]]return = [["true"],["true"],["true"],["READ","WRITE"],["db","repo"],["true"],["WRITE"],["true"],["db"]]

Revoking READ leaves WRITE intact. Revoking ALL then removes repo from the employee's resource list.

Constraints

  • 1 <= operations.length <= 100000
  • accessType is READ, WRITE, ADMIN, or ALL where allowed.

More Rippling problems

drafts saved locally
public String[][] manageEmployeeAccess(String[][] operations) {
  // write your code here
}
operations[["GRANT","e1","repo","READ"],["GRANT","e1","repo","WRITE"],["GRANT","e1","db","ADMIN"],["GET_ACCESS","e1","repo"],["GET_RESOURCES","e1"],["REVOKE","e1","repo","READ"],["GET_ACCESS","e1","repo"],["REVOKE","e1","repo","ALL"],["GET_RESOURCES","e1"]]
expected[["true", "true", "true", "READ", "WRITE", "db", "repo", "true", "WRITE", "true", "db"]]
checking account