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.
Input: start = 0, changes = [["grant","READ"],["grant","WRITE"],["revoke","READ"]] Output: 2
0 → 1 → 3 → 2: only WRITE is left.
Input: start = 31, changes = [["toggle","ADMIN"]] Output: 15
Everything was on; toggling ADMIN (16) turns it off: 31 ^ 16 = 15.
0 <= start <= 310 <= changes.length <= 100Run 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).
I'm here to help with #681 Apply Permission Changes. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.