2dbi
Home/Miro/Length of Last Word
MMiro·DSASWE-2Technical Phone Screen

Length of Last Word

Problem

Return the length of the last word in a string.

Example

"Hello World" -> 5

Constraints

  • 1 ≤ |s| ≤ 10^4

Approach

Trim trailing spaces, count back to the previous space. Reported Miro question.

added 6 days ago
LeadersAccount