Connection Status:
Competition Arena > Splicer
SRM 92 · 2002-05-27 · by dgoodman
Class Name: Splicer
Return Type: String
Method Name: splice
Arg Types: (string, string)
Problem Statement

Problem Statement

A DNA sequence is a sequence of letters from the set {A,C,T,G}. Define a "repeat sequence" to be a DNA sequence which consists entirely of a smaller DNA sequence concatenated 2 or more times. Create a class Splicer that contains the method splice that takes two DNA Strings as input and returns a String which is a repeat sequence made by splicing the two DNA strings together.
A splice consists of concatenating the two input strings in either order, or of inserting one of the inputs strings between adjacent characters of the other string. Splicing ACT with GA can result in ACTGA, GAACT, AGACT, ACGAT, or GACTA. If it is possible to produce more than one repeat sequence from the inputs, return the one that comes earliest alphabetically. If it is not possible to produce a repeat sequence, return the 10 character string "IMPOSSIBLE".

Constraints

  • s1 contains between 1 and 50 characters, inclusive.
  • s2 contains between 1 and 50 characters, inclusive.
  • s1 and s2 contain only the uppercase characters 'A','C','T','G'.
Examples
0)
"ACTT"
"AC"
Returns: "ACTACT"

Splice the "AC" into the "ACTT" between the last two characters.

1)
"AAAAAAT"
"TAAAT"
Returns: "AAATAAATAAAT"
2)
"ACGACGACG"
"GACA"
Returns: "IMPOSSIBLE"
3)
"ACACA"
"CAC"
Returns: "ACACACAC"

"CACACACA" is also possible, but is later than ACACACAC alphabetically.

4)
"ACTACT"
"ACTA"
Returns: "IMPOSSIBLE"

Submissions are judged against all 46 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Splicer with a public method string splice(string s1, string s2) · 46 test cases · 2 s / 256 MB per case

Submitting as anonymous