← SoFi Interview InsightsSoftware Engineer

SoFi·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

SoFi coding screen with a text-wrapping variant. Basically LeetCode 68 but without the justified padding, just greedy packing. Pretty straightforward if you've seen the original problem before.

Questions Asked (1)

Q1

Given an array of words and a max line width, group the words into lines greedily so each line fits within the width. No need to pad lines to a fixed length, just pack and return.

Algorithms & Data Structures
Author's notes

Simpler than the classic justify-text problem since you skip all the padding logic.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then walk through a greedy line-packing algorithm using a single pass. Emphasize maintaining the current line length and appending words until the next word would exceed the width, then start a new line.

Pro tip: Mention that this is essentially the greedy approach used in text justification (like LeetCode 68) but without padding, and note that the greedy choice is optimal for minimizing the number of lines. Also, discuss how you would handle edge cases like a word longer than the max width.

1. Clarify requirements and edge cases

Ask about input constraints: can words be longer than maxWidth? Should we handle empty input? Are there multiple spaces? Confirm that lines should not be padded and that we just return the packed lines.

2. Outline the greedy algorithm

Explain that you'll iterate through words, maintaining the current line and its length. For each word, check if adding it (plus a space if the line is non-empty) would exceed maxWidth. If so, finalize the current line and start a new one with the word.

3. Walk through an example

Choose a small example (e.g., words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16) and step through the algorithm to show how lines are formed.

4. Analyze complexity and edge cases

State that the time complexity is O(n) where n is the total number of characters, and space is O(n) for the output. Discuss handling a word longer than maxWidth (e.g., place it on its own line, possibly truncated or as is, depending on requirements).

5. Discuss potential optimizations or variations

Mention that if the input is a stream, you can process it on the fly. Also, note that if padding were required, the algorithm would need to distribute spaces, but here it's simpler.

Key Points to Mention

  • Greedy approach: always fit as many words as possible on the current line before moving to the next.
  • Tracking current line length: account for spaces between words when checking if the next word fits.
  • Edge cases: empty input, single word, word longer than maxWidth, and exact fit.
  • Time and space complexity: O(n) time and O(n) space for the output.
  • Comparison to text justification: this is a simplified version without padding.
  • Clarifying questions: confirm if words can be split or if they must remain intact.

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