Skip to the code
cf.
+10 XP

#17 Letter Tiles for a Banner

easy

A shop window display spells out banners with physical letter tiles. You have the tiles in tiles, one character per tile, and each tile can be used once.

Write canBuildBanner(banner, tiles) that returns true if every letter of banner can be covered by its own tile. Spaces in banner need no tile.

Example 1

Input: banner = "big sale", tiles = "selagibx"
Output: true

Every letter of big sale has a tile, and the extra x is fine.

Example 2

Input: banner = "hello", tiles = "helo"
Output: false

hello needs two l tiles but there is only one.

Constraints

  • 0 <= banner.length, tiles.length <= 10^5
  • banner has lowercase letters and spaces; tiles has lowercase letters.
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).