← Codeium Interview Insights

Codeium·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Codeium coding screen with one algorithmic question that sounds simple but has a sneaky tie-breaking rule baked in. The kind of problem where you think you're done and then realize you missed half of it.

Questions Asked (1)

Q1

Given an array of strings, return the third largest word by length. If words tie on length, prefer the one that appears later in the array.

Algorithms & Data Structures
Author's notes

I jumped straight into sorting by length descending and almost called it done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the tie-breaking rule and edge cases (e.g., fewer than three distinct lengths) before coding. Then, use a min-heap of size 3 to track the top three words by length, updating the heap when a longer word is found or when lengths tie and the current word appears later. Finally, return the word at the top of the heap (the third largest).

Pro tip: Mention that you can avoid a heap by maintaining three variables (first, second, third) for O(1) space, but a heap generalizes to k-th largest. Also, discuss how to handle duplicate words and the importance of stable tie-breaking.

1. Clarify requirements and edge cases

Ask about tie-breaking (later index wins), what to return if fewer than three words, and whether words can be empty or have equal lengths. Confirm that 'third largest' means third distinct length or third word in sorted order.

2. Choose data structure and algorithm

Decide between sorting (O(n log n)) or a min-heap of size 3 (O(n log 3) ≈ O(n)). For interviews, a heap is efficient and demonstrates understanding of priority queues.

3. Implement with careful tie-breaking

Iterate through the array, and for each word, compare its length with the smallest in the heap. If longer, replace; if equal, replace only if the current index is greater than the stored index. Store both length and index in the heap.

4. Handle edge cases and return result

If the heap has fewer than 3 elements after processing, return an empty string or as specified. Otherwise, return the word associated with the smallest element in the heap (the third largest).

5. Test with examples and analyze complexity

Walk through examples like ['a','bb','ccc','dddd'] and ties like ['a','bb','cc','dd'] to verify tie-breaking. State time complexity O(n log 3) and space O(1) (or O(k) for general k).

Key Points to Mention

  • Tie-breaking rule: later index wins when lengths are equal.
  • Use a min-heap of size 3 to efficiently track top three words.
  • Store both length and index in the heap to handle ties correctly.
  • Edge cases: fewer than three words, empty strings, all words same length.
  • Time complexity O(n log 3) ≈ O(n) and space O(1) for fixed k=3.
  • Alternative: sorting approach O(n log n) but less efficient for large n.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.