#include <bits/stdc++.h>
using namespace std;
int lengthOfLastWord(string s) {
int len = s.length();
int i = len - 1, j = 0;
//ignore the right spaces
while(s[i] == ' '){
i--;
}
// go till a space is not found
while(i >=0 && ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))){
i--;
j++;
}
return j;
}
int main() {
cout << lengthOfLastWord("hello world");
cout << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbGVuZ3RoT2ZMYXN0V29yZChzdHJpbmcgcykgewogICAgaW50IGxlbiA9IHMubGVuZ3RoKCk7CiAgICBpbnQgaSA9IGxlbiAtIDEsIGogPSAwOwogICAgLy9pZ25vcmUgdGhlIHJpZ2h0IHNwYWNlcwogICAgd2hpbGUoc1tpXSA9PSAnICcpewogICAgICAgIGktLTsKICAgIH0KICAgIC8vIGdvIHRpbGwgYSBzcGFjZSBpcyBub3QgZm91bmQKICAgIHdoaWxlKGkgPj0wICYmICgoc1tpXSA+PSAnYScgJiYgc1tpXSA8PSAneicpIHx8IChzW2ldID49ICdBJyAmJiBzW2ldIDw9ICdaJykpKXsKICAgICAgICBpLS07CiAgICAgICAgaisrOwogICAgfQogICAgcmV0dXJuIGo7Cn0KCmludCBtYWluKCkgewoJY291dCA8PCBsZW5ndGhPZkxhc3RXb3JkKCJoZWxsbyB3b3JsZCIpOwoJY291dCA8PCBlbmRsOwoJcmV0dXJuIDA7Cn0=