Longest Word in Sentence
Hard
strings
arrays
Description
Find and return the longest word in a sentence. If there are ties in length, return the first longest word found. The result should be a cleaned word (no punctuation).
Examples
Example1:
Input: 'Find the longest word here'
Output: 'longest'
Explanation: The words are 'Find' (4), 'the' (3), 'longest' (7), 'word' (4), 'here' (4). Longest is 'longest'.
Example2:
Input: 'Hello, world!'
Output: 'Hello'
Explanation: Punctuation is ignored. Both 'Hello' and 'world' are length 5. 'Hello' comes first.
Constraints
- Input is a string.
- Output is a string.
- Handle punctuation attached to words (e.g., 'word!' should be 'word').
Test Case 1
Input: "Find the longest word here"
Output: "longest"
Test Case 2
Input: "A quick brown fox"
Output: "quick"
Test Case 3
Input: "The longest one, is this word."
Output: "longest"
