TopcoderArchiveVisit Topcoder
SRM26 Jan 2020
SRM 777

StringTransformationEasy

Problem statement, definition, constraints, and public examples.

Problem Statement

You have a sequence of red and green balls. The sequence is described by the String s: red balls are denoted 'R' and green ones 'G'. You would like to transform s into the target String t.

The only transformation allowed looks as follows: Let p,q,r,s be four consecutive balls. If balls q and r have the same color and at the same time balls p and s have different colors, you may remove the balls q and r.

Formally, you may choose an index i such that s[i+1] = s[i+2] and at the same time s[i] != s[i+3]. If you do, you may remove the characters at indices i+1 and i+2 from s.

Return "YES" (quotes for clarity) if there is a sequence of zero or more transformations that converts s into t. Otherwise, return "NO".

Definition

Class:
StringTransformationEasy
Method:
getResult
Parameters:
String, String
Returns:
String
Method signature:
String getResult(String s, String t)
(be sure your method is public)

Constraints

  • s and t will contain between 1 and 2,500 characters.
  • s and t will consist only of characters R and G.

Examples

  1. "RRRRGGG"
    "RRG"
    Returns: "YES"
  2. "RRR"
    "RRR"
    Returns: "YES"
  3. "RRRGGRRRRGGG"
    "RGGRRRRG"
    Returns: "YES"
  4. "RRGG"
    "RRGGGG"
    Returns: "NO"
  5. "GGGG"
    "GG"
    Returns: "NO"
Back to all problems