← EvenUp Interview Insights

EvenUp·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Got a coding question at EvenUp for a Software Engineer role, just the one problem about string compression. Pretty standard algorithmic stuff but the in-place constraint is where things get tricky if you're not careful.

Questions Asked (1)

Q1

Given an array of characters, compress it in place so that consecutive repeated characters are replaced by the character followed by its count (omitting the count if the group is just one character). Return the new length of the array, using only constant extra space.

Algorithms & Data Structures
Author's notes

The base logic isn't that bad, you walk through groups and write back.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique: one pointer (read) scans the array to identify groups of consecutive identical characters, while the other pointer (write) writes the compressed output in place. For each group, write the character and, if the count is greater than 1, write the count as individual digits. Return the write pointer as the new length.

Pro tip: Emphasize that the count can be multi-digit, so you must convert it to characters digit by digit; also mention that the write pointer never overtakes the read pointer, ensuring constant space.

1. Initialize pointers

Set read and write pointers to 0. The read pointer will scan the original array, and the write pointer will track the position for the next compressed character.

2. Scan groups

While read < length, record the current character and count consecutive occurrences by advancing read until a different character is found.

3. Write character

Write the current character at the write pointer and increment write.

4. Write count if needed

If the count is greater than 1, convert the count to a string (or extract digits) and write each digit at the write pointer, incrementing write for each digit.

5. Return new length

After processing all groups, return the write pointer as the new length of the compressed array.

Key Points to Mention

  • Two-pointer technique for in-place modification
  • Handling multi-digit counts (e.g., 12 becomes '1' and '2')
  • Constant extra space (O(1))
  • Time complexity O(n) where n is the array length
  • Edge cases: empty array, single character, all same characters
  • In-place means modifying the input array directly without using additional arrays

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