TopcoderARCHIVE
Archive/Problems/SimplestCrossword
SRM · Problem 16618

SimplestCrossword

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given two Strings: H and V. Build the simplest possible crossword that contains these two strings and nothing else. H must appear horizontally, V must appear vertically, and the two strings must overlap somewhere. The crossword must be rectangular and it must be as small as possible.

Return the crossword as a String[], using '.' for cells that do not contain a letter. If there are multiple valid solutions, you may return any one of them. If there is no valid solution, return an empty String[] instead.

Definition

Class:
SimplestCrossword
Method:
construct
Parameters:
String, String
Returns:
String[]
Method signature:
String[] construct(String H, String V)
(be sure your method is public)

Constraints

  • H will contain between 2 and 10 characters, inclusive.
  • V will contain between 2 and 10 characters, inclusive.
  • Each character in H and V will be an uppercase English letter ('A'-'Z').

Examples

  1. "TOP"
    "CODER"
    Returns: {".C.", "TOP", ".D.", ".E.", ".R." }
    This is what the return value looks like when formatted into a rectangle: {".C.", "TOP", ".D.", ".E.", ".R." } This return value describes the following crossword: .C. TOP .D. .E. .R. In this particular test case, this is the only valid solution.
  2. "CODER"
    "TOP"
    Returns: {".T...", "CODER", ".P..." }
    Here we swapped the two words, so now CODER should go horizontally. The returned crossword looks as follows: .T... CODER .P...
  3. "AAAAA"
    "AAAAAA"
    Returns: {"...A.", "...A.", "...A.", "AAAAA", "...A.", "...A." }
    Returned crossword: ...A. ...A. ...A. AAAAA ...A. ...A. In this case there are 29 other valid crosswords, and each of those would be accepted as well.
  4. "CAT"
    "DOG"
    Returns: { }
    We cannot make these two words overlap.
← All problems