Problem with test case?


#1

`string Solution::solve(string A) {

int n=A.length();
if(n==0)return "";
else if(n==1 && A[0]!=' ')return A;
int i=-1,j=0;
vector<string> v;
while(j<n)
{
    if(A[j]==32){
        if(j==i+1){
            i++;continue;
        }
        
        v.push_back(A.substr(i+1,j-i-1));
        while(j<n && A[j]==' ' && A[j+1]==' '){
            j++;
        }
        i = j;
    }
    j++;
}
v.push_back(A.substr(i+1,j-i-1));
string ans="";
for(int k=v.size()-1;k>=0;k--)
{
    if(k==0)
    {
        ans =ans + v[k];
    }
    else{
        ans = ans+v[k]+" ";
    }
}
return ans;

}
`

My code gives a problem with the following test case.
" fwbpudnbrozzifml osdt ulc jsx kxorifrhubk ouhsuhf sswz qfho dqmy sn myq igjgip iwfcqq "
So basically I’m getting my reversed string plus the original string.Can anybody solve the doubt???


#2

Same problem
i used string erase spaces also but it didnt work.