Permission bitmask decoder

Write codeMedium12 min

Your task

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"].

Examples

decode_permissions(mask: int, flags: list[str]) -> list[str]
Example 1
Inputdecode_permissions(5, ["read", "write", "delete"])
Output["read", "delete"]
Example 2
Inputdecode_permissions(10, ["r", "w", "x", "admin"])
Output["w", "admin"]