Find the Longest Even-Length Word

Quick Overview

Implement `longest_even_word(sentence)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

Find the Longest Even-Length Word

Company: Walmart Labs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

# Find the Longest Even-Length Word Implement `longest_even_word(sentence)`. Words are separated by one or more spaces. Return the first word among those having the greatest positive even length. Return `"00"` when `sentence` is empty, contains only spaces, or contains no even-length word. The input is always a non-null string in every language. Examples: - `"Time to write great code"` returns `"Time"`. - `"a cat sun"` returns `"00"`. Constraints: at most `200000` characters; words contain English letters. Process the sentence in one pass over its words. ```hint Preserve first-on-tie behavior Update the answer only when a strictly longer eligible word appears. ```

Quick Answer: Implement `longest_even_word(sentence)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

|Home/Coding & Algorithms/Walmart Labs
Walmart Labs logo
Walmart Labs
Aug 11, 2026, 12:00 AM
easySoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Find the Longest Even-Length Word

Implement longest_even_word(sentence). Words are separated by one or more spaces. Return the first word among those having the greatest positive even length. Return "00" when sentence is empty, contains only spaces, or contains no even-length word. The input is always a non-null string in every language.

Examples:

  • "Time to write great code" returns "Time" .
  • "a cat sun" returns "00" .

Constraints: at most 200000 characters; words contain English letters. Process the sentence in one pass over its words.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...