Permission bitmask decoder
The same access-control service must display a user's permissions as human-readable names. Given a non-negative bitmask and the ordered list of permission names (the name at index i corresponds to bit i), return the list of names whose bits are set in the mask, in flag-list order. The mask may have set bits beyond the last known name — perhaps written by a newer service version — and those must be ignored. For example, mask 5 with ["read", "write", "delete"] returns ["read", "delete"].
Implement
decode_permissions(mask: int, flags: list[str]) → list[str]Examples
in
[5,["read","write","delete"]]out["read","delete"]in
[10,["r","w","x","admin"]]out["w","admin"]What a strong answer looks like
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.
0:00 of about 12 min
solution.py
InputExpectedGot
[5,["read","write","delete"]]["read","delete"]not run yetsample[10,["r","w","x","admin"]]["w","admin"]not run yetsample