Permission bitmask encoder

Write codeEasy12 min

Your task

An access-control service stores each user's permissions as one integer bitmask. You are given the ordered list of permission names for a resource, the name at index i corresponds to bit i, and the list of names granted to a user (each granted name appears in the flag list; no duplicates). Return the bitmask encoding the grant. For example, with flags ["read", "write", "delete"] and granted ["read", "delete"], bits 0 and 2 are set, so return 5.

Examples

encode_permissions(flags: list[str], granted: list[str]) -> int
Example 1
Inputencode_permissions(["read", "write", "delete"], ["read", "delete"])
Output5
Example 2
Inputencode_permissions(["r", "w", "x", "admin"], ["admin", "w"])
Output10