Skip to the code
cf.
+10 XP

#22 Shared Permissions

easy

An admin panel compares two roles. Each role's permissions are listed in a and b, possibly with repeats.

Write sharedPermissions(a, b) that returns every permission that appears in both lists, each once, sorted in normal string order.

Example 1

Input: a = ["read","write","delete"], b = ["write","admin","read"]
Output: ["read","write"]

read and write are in both roles.

Example 2

Input: a = ["view"], b = ["edit"]
Output: []

The roles share nothing.

Constraints

  • 0 <= a.length, b.length <= 10^5
  • Permissions are lowercase strings.
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).