TopcoderARCHIVE
Archive/Problems/BuildString
SRM · Problem 17862

BuildString

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a String[] parts. You are also given a String target. The goal will be to use some or all of the parts to concatenate together to build the target string. You may use the same part multiple times, and it is not necessary to use all of the parts.

Return "YES" if it is possible to build the target string, otherwise return "NO".

Definition

Class:
BuildString
Method:
isPossible
Parameters:
String[], String
Returns:
String
Method signature:
String isPossible(String[] parts, String target)
(be sure your method is public)

Constraints

  • parts will contain between 1 and 50 elements, inclusive.
  • Each element of parts will contain between 1 and 50 uppercase ('A'-'Z') characters, inclusive.
  • target will contain between 1 and 50 uppercase ('A'-'Z') characters, inclusive.

Examples

  1. { "TOP", "CODER" }
    "TOPCODER"
    Returns: "YES"
    It's trivial to concatenate the two strings together.
  2. { "BOTTOM", "CODER" }
    "TOPCODER"
    Returns: "NO"
    This time it won't work.
  3. { "ISS", "M", "IPPI" }
    "MISSISSIPPI"
    Returns: "YES"
    Notice that we use "ISS" more than once, and that we're not using the parts in order.
  4. { "A", "B", "C", "D", "R" }
    "ABBACADABRA"
    Returns: "YES"
← All problems