Length of Last Word (LeetCode 58): Interview Notes

Given a string s consisting of words and spaces, return the length of the last word.

Scan from the end, skip trailing spaces, then count until the next space or start.

Time O(n), space O(1). Easy warm-up before string parsing questions.

When you want live practice with follow-ups, try Linkjob.ai.

Disclosure: I work on Linkjob AI.