classSolution{ fun minStickers(stickers: Array<String>, target: String): Int { val n = target.length val m = 1 shl n val dp = IntArray(m) { Int.MAX_VALUE } dp[0] = 0 for (i in 0 until m) { if (dp[i] == Int.MAX_VALUE) continue for (sticker in stickers) { var cur = i for (c in sticker) { for (j in target.indices) { if (target[j] == c && cur shr j and 1 == 0) { cur = cur or(1 shl j) break } } } dp[cur] = min(dp[cur], dp[i] + 1) } } returnif (dp[m - 1] == Int.MAX_VALUE) -1else dp[m - 1] } }