← Convoy Interview Insights

Convoy·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Convoy coding interview for a software engineer role, focused on an in-place string compression problem. The follow-up questions were more demanding than the main problem itself.

Questions Asked (1)

Q1

Given an array of characters, compress it in-place using run-length encoding: for each consecutive run of the same character, write the character followed by the run length as individual digit characters (omit the count if the run length is 1). Return the new length of the modified array. You must use O(1) extra space.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core problem wasn't too bad once I realized I needed two pointers, one for reading and one for writing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer approach: one pointer reads through the array to identify runs, and another writes the compressed result in-place. For each run, write the character, then if the run length is greater than 1, write each digit of the count as a separate character. Return the write pointer as the new length.

Pro tip: Clarify with the interviewer whether the input array is mutable and whether the compressed result must overwrite the original array from the beginning. Also, discuss edge cases like empty array, single character, and runs longer than 9 to show thoroughness.

1. Understand the problem and constraints

Restate the problem to ensure clarity: compress runs in-place, O(1) extra space, and return new length. Ask clarifying questions about input mutability and expected output format.

2. Design the two-pointer approach

Initialize a write pointer at 0 and a read pointer at 0. Iterate through the array to find the end of each run, then write the character and its count (if >1) at the write pointer, advancing it accordingly.

3. Handle digit conversion and edge cases

For run lengths >1, convert the integer count to a string and write each digit as a character. Consider edge cases: empty array, runs of length 1, and runs longer than 9 (multi-digit counts).

4. Implement and test with examples

Write clean code, then walk through examples like ['a','a','b','b','c','c','c'] to verify correctness. Ensure the write pointer never overtakes the read pointer to avoid overwriting unprocessed data.

5. Analyze complexity and trade-offs

State that time complexity is O(n) and space complexity is O(1). Discuss potential trade-offs, such as readability vs. in-place efficiency, and mention alternative approaches if extra space were allowed.

Key Points to Mention

  • Two-pointer technique for in-place modification
  • O(1) extra space constraint and how it's satisfied
  • Handling multi-digit run lengths (e.g., 12 becomes '1','2')
  • Edge cases: empty array, single character, all same characters
  • Time complexity O(n) and space complexity O(1)
  • In-place overwriting safety: write pointer never exceeds read pointer

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