Super Reduced String

See the original problem on HackerRank.

Solutions

A solution changes the string by removing same adjacent elements.

Here is a C++ implementation:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  #include #include #include using namespace std; int main() { string S; cin >> S; auto finder = [&]{ return adjacent_find(begin(S), end(S)); }; for (auto adjFind = finder(); adjFind != end(S); adjFind = finder()) { S.erase(adjFind, adjFind + 2); } cout << (S.empty() ? "Empty String" : S); } 

An alternative solution that does not modify the input uses an additional data structures:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  #include #include #include #include using namespace std; int main() { string S; cin >> S; deque st; for (auto i=0; i
We've worked on this challenge in these gyms: modena