Longest Even Word
Preview mode. Log in to edit, run, submit, and save progress.
Easy
Longest Even Word
A sentence is made of words separated by spaces. Your task is to find the longest word whose length is even. If multiple even-length words share the maximum length, return the one that appears first. If the sentence does not contain any even-length word, return -1.
Examples
Example 1
Input:
Time to write great code
Output:
Time
Explanation: The even-length words are Time, to, and code. Time and code both have length 4, but Time appears first.
Approach hint
Split the sentence into words.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
solution.cpp