Skip to the code
cf.
+10 XP

#15 Shuffled Class Name Check

easy

A CSS linter wants to flag class names that are just another class name with its characters shuffled.

Write sameLetters(a, b) that returns true if b uses exactly the same characters as a, each the same number of times, in any order. Upper and lower case count as different characters.

Example 1

Input: a = "btn-primary", b = "primary-btn"
Output: true

Both strings use the same characters the same number of times.

Example 2

Input: a = "card", b = "cart"
Output: false

card has a d and cart has a t.

Constraints

  • 0 <= a.length, b.length <= 10^5
  • Strings contain printable ASCII characters.
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).