Problem · String
Longest Even-Length Word
Learn this problemProblem statement
Return the longest even-length word in a nullable text value. Words are maximal non-empty runs of non-whitespace ASCII characters. If several words share the greatest even length, return the first one.
Nullable text representation
The parameter textInput contains either zero or one string:
- An empty array represents a
nulltext value. - A one-element array contains the text to inspect; its string may itself be empty.
Return the literal string "00" when the text is null, empty, contains only whitespace, or contains no even-length word.
Function
longestEvenLengthWord(textInput: String[]) → StringExamples
Example 1
textInput = ["Time to write great code"]return = "Time"The even-length words are "Time", "to", and "code". The greatest even length is 4; "Time" appears before "code".
Example 2
textInput = ["a bb\tcccc dddd"]return = "cccc"Repeated whitespace creates no empty words. Both "cccc" and "dddd" have length 4, so the first one is returned.
Example 3
textInput = []return = "00"An empty textInput represents a null text value, so the required fallback is returned.
Constraints
0 <= textInput.length <= 1.- When present,
0 <= textInput[0].length <= 2 * 10^5. - The text contains ASCII characters only.
- Whitespace delimiters are ASCII space, tab, line feed, carriage return, form feed, and vertical tab characters.
- Word length is measured in ASCII characters.