Given a set of strings (building blocks), find the length of the smallest string such that there is more than one way to build it.

Revision en1, by pabloskimg, 2021-06-10 00:56:10

For example, if the set of building block strings is {"10", "01", "101"}, the smallest string that can be formed in multiple ways is "10101", since it can be constructed by concatenating "10" + "101" or "101" + "01". Therefore, the answer is 5. However, in the case of the set {"AB", "BA", "ABB"}, there is no string that can be constructed in multiple ways from the building blocks. Therefore, the answer in this case is -1.

How can we solve this problem?

Tags #string

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English pabloskimg 2021-06-10 00:56:10 589 Initial revision (published)