Role permission resolver
An admin console hands every teammate a set of roles, and roles borrow from one another. Each entry of inherits is written role:base and means that role picks up everything base has, including whatever base borrowed in turn. Each entry of grants is written role=permission and gives that role one permission directly. Role names never contain a colon or an equals sign, and permission names never contain an equals sign. The console does not check the borrowing for loops, so a chain can come back on itself and the resolver still has to finish. Given inherits, grants and member_roles, return every distinct permission the teammate ends up holding, sorted in ascending order. A role nobody granted anything to contributes nothing, and a role named in member_roles that appears nowhere else contributes nothing. Return an empty list when the teammate holds no permissions.
effective_permission_set(inherits: list[str], grants: list[str], member_roles: list[str]) → list[str][["support-lead:support","admin:support-lead"],["support=ticket.read","support-lead=ticket.close","admin=user.delete"],["admin"]]out["ticket.close","ticket.read","user.delete"][["analyst:viewer"],["viewer=report.read","analyst=report.export"],["viewer"]]out["report.read"][["lead:eng","lead:oncall"],["eng=repo.read","oncall=page.ack","lead=repo.read"],["lead"]]out["page.ack","repo.read"]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["support-lead:support","admin:support-lead"],["support=ticket.read","support-lead=ticket.close","admin=user.delete"],["admin"]]["ticket.close","ticket.read","user.delete"]not run yetsample[["analyst:viewer"],["viewer=report.read","analyst=report.export"],["viewer"]]["report.read"]not run yetsample[["lead:eng","lead:oncall"],["eng=repo.read","oncall=page.ack","lead=repo.read"],["lead"]]["page.ack","repo.read"]not run yetsample