← Capital One Interview Insights

Capital One·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Capital One SWE interview with a text justification coding problem. Pretty standard algorithmic question but the edge cases will get you if you're not careful.

Questions Asked (1)

Q1

Implement a function that takes a list of words and a maximum line width, and returns the words justified to fit within that width.

Algorithms & Data Structures
Author's notes

I jumped straight into the greedy packing logic and felt good about it, then completely fumbled the spacing distribution.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact justification rules (e.g., left-justify last line, distribute spaces evenly, handle single-word lines) and edge cases. Then outline a greedy line-packing algorithm: iterate through words, accumulate until adding the next word exceeds the width, then justify the current line by distributing spaces. Finally, discuss time/space complexity and test with examples.

Pro tip: Mention that you would handle the last line specially (left-justified, no extra spaces) and that you'd consider whether extra spaces go to the left or right gaps—this shows attention to detail and real-world text formatting.

1. Clarify requirements and edge cases

Ask about justification rules: should spaces be distributed evenly? What about the last line? How to handle a single word that exceeds the width? Confirm input/output format.

2. Design the line-packing algorithm

Use a greedy approach: iterate through words, adding them to a current line until the next word would exceed the max width. Then finalize the line.

3. Implement justification for each line

For non-last lines, compute total spaces needed and distribute them as evenly as possible, with extra spaces going to the leftmost gaps. For the last line, left-justify with single spaces.

4. Analyze complexity and test

State time complexity O(n) where n is total characters, and space O(n) for output. Walk through a small example to verify correctness, including edge cases.

Key Points to Mention

  • Greedy line packing: fit as many words as possible per line without exceeding width.
  • Space distribution: calculate total spaces needed, divide by number of gaps, distribute remainder to leftmost gaps.
  • Last line handling: left-justify with single spaces, no extra padding.
  • Edge cases: single word longer than width, empty input, width smaller than any word.
  • Time and space complexity: O(n) time and O(n) space for output.
  • Modular code: separate functions for line packing and justification for readability.

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