question:
answer:
Hey @aarijrab
You can do this in one i++ also
Here see this
class Solution{
public:
string firstAlphabet(string S)
{
// Your code goes here
string str="";
if(S[0]!=' ')
str+=S[0];
int i=1;
while(i<S.length())
{
if(S[i]==' ')
{
if(i+1<S.length())
{
str+=S[i+1];
// i++;(we can do this because we know that next char cant be first letter again so you can say its lil bit of optimization)
}
// i++; (removed from here because in else too we are doing i++
}
// else (removed else because we want to do i++ in both anyway)
i++;
}
return str;
}
};
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.