MakeTwoConsecutive
SRM 727 · 2018-01-10 · by Errichto
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
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'.
"VIKING" Returns: "Possible"
You can remove 'K' to obtain the string "VIING". This string is beautiful because it has two consecutive 'I'.
"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".
"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.
"A" Returns: "Impossible"
After removing one character you will get the empty string "". It isn't beautiful.
"AABB" Returns: "Possible"
You can get either "ABB" or "ABB". Both these strings are beautiful.
"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.
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