Description

Given n types of stickers (each with lowercase letters) and a target string, return the minimum number of stickers needed to spell target, or -1 if impossible.

Examples

Input:stickers = ["with","example","science"], target = "thehat"
Output:3
Explanation:

Use 'with' twice and 'example' once.

Input:stickers = ["notice", "possible"], target = "basicstep"
Output:-1
Explanation:

Spelling 'basicstep' requires letters 'b' and 'p' which do not appear in either 'notice' or 'possible'. Since these letters cannot be obtained from any sticker, the task is impossible, returning -1.

Input:stickers = ["control", "heart", "madle"], target = "mother"
Output:3
Explanation:

Use 'madle' for 'm', 'control' for 'o' and 't', and 'heart' for 'h', 'e', and 'r'. Each sticker is used once for a total of 3 stickers.

Constraints

  • n == stickers.length
  • 1 ≤ n ≤ 50
  • 1 ≤ stickers[i].length ≤ 10

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!