DoubleLetter
SRM 630 · 2014-07-26 · by cgy4ever
SRM 630 · 2014-07-26 · by cgy4ever · Greedy
Problem Statement
Problem Statement
You are given a String S.
You can modify this string by repeating the following process:
- Find the leftmost occurrence of two consecutive letters in S that are the same.
- If you found a pair of identical letters in the first step, delete those two letters from S.
- Find and erase "aa", producing the string "bccb".
- Find and erase "cc", producing the string "bb".
- Find and erase "bb", producing the empty string.
Constraints
- S will contain between 1 and 50 characters.
- Each character in S will be a lowercase English letter ('a'-'z').
Examples
0)
"aabccb" Returns: "Possible"
1)
"aabccbb" Returns: "Impossible"
The process will terminate with a single 'b'.
2)
"abcddcba" Returns: "Possible"
"abcddcba" -> "abccba" -> "abba" -> "aa" -> "".
3)
"abab" Returns: "Impossible"
No two successive letters are the same, so we can't do any operation.
4)
"aaaaaaaaaa" Returns: "Possible"
Submissions are judged against all 106 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class DoubleLetter with a public method string ableToSolve(string S) · 106 test cases · 2 s / 256 MB per case