← All problemsSign in

3291. Minimum Number of Valid Strings to Form Target I

LeetCodeArrayStringBinary SearchDynamic ProgrammingGreedyTrieOpen on judge ↗

You are given an array of strings words and a string target. A string x is called valid if x is a prefix of any string in words. Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1. Example 1: Input: words = ["abc","aaaaa","bcdef"], target = "aabcdabc" Output: 3 Explanation: The target string can be formed by

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start