Coding questions · Codeium
Find the third-largest word by length
This question evaluates proficiency in string and array manipulation, ordering by key metrics (string length), and handling tie-breaking via stable ordering, situated in the Coding & Algorithms domain.
Given an array of strings strArr (length ≥ 3), return the third largest word when ranking words by string length in descending order.
Ranking rules:
- Larger length ⇒ larger rank.
- If two words have the same length, keep their original left-to-right order from the input (i.e., use a stable sort by length descending).
- After ranking, return the word at rank 3 (the 3rd element in this ordering).
Assumptions/constraints:
- Each string contains only letters.
- The input contains at least 3 strings.
Examples:
- Input:
["hello", "world", "before", "all"]→ Output:"world" - Input:
["hello", "world", "after", "all"]→ Output:"after" - Input:
["coder", "byte", "code"]→ Output:"code" - Input:
["abc", "defg", "z", "hijk"]→ Output:"abc"
Third Largest Word By Length
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.