Given a sentence s, return the longest word. If several words share the greatest length, return the one that appears first. Words are separated by spaces and punctuation attached to a word counts as part of it. Return "" if there are no words.
Examples
Input: s = "I love programming in Python"
Output: "programming"
Input: s = "red blue green"
Output: "green"
Constraints
0 <= len(s) <= 5000smay contain letters, digits, spaces and punctuation
Goals
- Iterate over words and track the best so far
- Break ties by keeping the earliest word