Longest Even-Length Word
Updated
Problem 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.
More Walmart Phone Screen questions
- Count Months Starting on SundayPHONE SCREEN · Seen Aug 2026
- Range ModulePHONE SCREEN · Seen Aug 2026
- Meeting Rooms IIPHONE SCREEN · Seen Aug 2026
- Sort Real Number StringsPHONE SCREEN · Seen Jan 2026
- Check a Password Against a Supplied PolicyPHONE SCREEN · Seen Jun 2025
- Convert a Restricted Function to an Arrow FunctionPHONE SCREEN · Seen Jun 2025
- Repair One Missing Function Punctuation CharacterPHONE SCREEN · Seen Jun 2025
- Can the Singer Perform the Song?PHONE SCREEN · Seen Mar 2025
- Rooms With Two Other Entrances and a Treasure SuccessorPHONE SCREEN · Seen Mar 2025
- First Dictionary Word from Note LettersPHONE SCREEN · Seen Aug 2022
Similar questions at other companies
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Run-Length DecodingApple · PHONE SCREENApple interview questions
- Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions
- Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
- Decode and Store StringsAirbnb · PHONE SCREENAirbnb interview questions
- Delimiter-Parsing String Iteratoramo · PHONE SCREEN