Super Reduced String

  • + 0 comments

    FASTEST Solution

    include

    using namespace std;

    char str[101]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    cin >> str;
    
    int top = 0, index = 0;
    while(str[++index] != '\0') {
        if(top < 0 || str[index] != str[top]) str[++top] = str[index];
        else --top; 
    }
    
    if(top < 0) { cout << "Empty String" << endl; return 0; }
    str[top + 1] = '\0';
    cout << str << endl; 
    return 0; 
    

    }