Ransom Note
Real-world version: Spell It With TilesThe statement here is our own: the same inputs, outputs and technique.
A signmaker's kit holds a jumble of engraved letter tiles. The string tiles lists what the kit contains, one lowercase character per tile, in no particular arrangement. A customer orders the label word, which has to be laid along a display rail exactly as written.
Every tile is a physical piece, so a tile placed on the rail is no longer in the kit; a label needing the same letter three times needs three separate tiles carrying it. Tiles left over in the kit are fine and the order they sit in never matters.
Report true when the kit can cover the whole label, and false when it runs short.
Examples
Example 1
- Input
- word = "kite", tiles = "tickle"
- Output
- true
The kit carries a k, an i, a t and an e, which is everything the label asks for.
Example 2
- Input
- word = "peer", tiles = "prime"
- Output
- false
The label wants two e tiles and the kit only holds one, so it runs short.
Example 3
- Input
- word = "cat", tiles = "tactic"
- Output
- true
Three of the six tiles cover the label and the leftovers stay in the kit.
Constraints
- 1 <= word.length, tiles.length <= 10^5
- word and tiles hold lowercase English letters only.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def can_construct(word: str, tiles: str) -> bool:public boolean canConstruct(String word, String tiles)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- First Unique Character in a StringReal-world version: First Solo StopEasy
- Maximum Number of BalloonsReal-world version: Kettle Signs from the Tile TrayEasy
- Find Words That Can Be Formed by CharactersReal-world version: Signs Spellable From A Tile TrayEasy
- Substrings of Size Three with Distinct CharactersReal-world version: Three Clean Pigment WindowsEasy