Skip to the code
cf.
+10 XP

#681 Apply Permission Changes

easy

A team-settings page stores a member's permissions as a bit mask: READ is 1, WRITE is 2, DELETE is 4, SHARE is 8, and ADMIN is 16.

changes is a list of [action, permission] pairs applied in order to start. action is "grant" (turn on), "revoke" (turn off), or "toggle" (flip). Write applyChanges(start, changes) that returns the final mask.

Example 1

Input: start = 0, changes = [["grant","READ"],["grant","WRITE"],["revoke","READ"]]
Output: 2

0 → 1 → 3 → 2: only WRITE is left.

Example 2

Input: start = 31, changes = [["toggle","ADMIN"]]
Output: 15

Everything was on; toggling ADMIN (16) turns it off: 31 ^ 16 = 15.

Constraints

  • 0 <= start <= 31
  • 0 <= changes.length <= 100
  • Permissions are one of the five names above.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).