message out of cut-out letters. You have as many copies of a newspaper as you like, all with the same headline headline.
From one copy you may cut any letters of the headline, but they go into the note **in the same order** they had in the headline (each copy provides a subsequence of headline). Pieces from different copies are glued one after another.
Return the smallest number of copies needed to build message, or -1 if it cannot be done.headline="rain", message="ranin" → 2
Cut "ran" (r, a, n) from the first copy and "in" from the second. Two copies suffice; one does not.
headline="news", message="sun" → -1
The headline has no letter u, so the note cannot be made.
headline="ab", message="bbb" → 3
Each copy yields just one b, so three copies are needed.
headline="rain", message="ranin"
2
Run checks the first 3 tests in your browser. Submit checks all 158 tests on the server, hidden ones included.