Question: Airtel Payments Bank, Online Assessment Questions ( 16th August 2023 - SET 3) | String Shortening | Branching and Palindrome
1
Entering edit mode

ADD COMMENTlink 13 months ago PoGo 2.4k
Entering edit mode
3

Answer to question-1

 

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    cin>>s;
    
    stack<char> st;
    
    for(int i=0;i<s.size();i++)
    {
        if(st.size()==0 || st.top()!=s[i])
        {
            st.push(s[i]);
        }
        else
        {
            st.pop();
        }
    }
    
    if(st.size()==0)
    {
        cout<<"Empty String";
    }
    else
    {
        string x="";
        while(!st.empty())
        {
            x+=st.top();
            st.pop();
        }
        
        reverse(x.begin(),x.end());
        cout<<x;
    }
    return 0;
}
 

ADD REPLYlink 13 months ago
Aayush Agrawal
• 180
0
Entering edit mode

add the test cases for question 2 !!!

 

ADD COMMENTlink 12 months ago kk • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts