#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;
}