We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In CPP:
/*
* Complete the 'superReducedString' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
string superReducedString(string s) {
int i = 0;
while (i < s.length()) {
char current_char = s[i];
char next_char = s[i+1];
if (current_char == next_char) {
s.erase(i,2);
if (i > 0) {
i -= 1;
}
} else{
i += 1;
}
}
if (s.empty()) {
return "Empty String";
} else{
return s;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
In CPP: /* * Complete the 'superReducedString' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */
string superReducedString(string s) { int i = 0;
}