Connection Status:
Competition Arena > MakeTwoConsecutive
SRM 727 · 2018-01-10 · by Errichto · Brute Force, Simple Search, Iteration, String Manipulation
Class Name: MakeTwoConsecutive
Return Type: String
Method Name: solve
Arg Types: (string)
Problem Statement

Problem Statement

Definition: a string is beautiful if it has two consecutive equal characters. Examples of beautiful strings are "KEEP", "ZZZZZ" and "TTORR", while the following are not beautiful: "A", "GH" and "ABCABCBX".


You are given the String S and you are going to remove exactly one character from S. Is it possible that the new string will be beautiful? If yes, return "Possible". Otherwise, return "Impossible".


Note that the return value is case-sensitive.

Constraints

  • S will contain between 1 and 50 characters, inclusive.
  • Each character in S will be an uppercase English letter: 'A' - 'Z'.
Examples
0)
"VIKING"
Returns: "Possible"

You can remove 'K' to obtain the string "VIING". This string is beautiful because it has two consecutive 'I'.

1)
"BCAB"
Returns: "Impossible"

You can only get one of the following strings: "CAB", "BAB", "BCB" and "BCA". None of these are beautiful, so the answer is "Impossible".

2)
"XX"
Returns: "Impossible"

After removing one character you will get the string "X" that isn't beautiful. Please note that you have to remove exactly one character.

3)
"A"
Returns: "Impossible"

After removing one character you will get the empty string "". It isn't beautiful.

4)
"AABB"
Returns: "Possible"

You can get either "ABB" or "ABB". Both these strings are beautiful.

5)
"QWERTYY"
Returns: "Possible"

There are a few beautiful strings you can get. Some of them are "WERTYY" and "QWETYY".

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

Coding Area

Language: C++17 · define a public class MakeTwoConsecutive with a public method string solve(string S) · 58 test cases · 2 s / 256 MB per case

Submitting as anonymous