Reported December 2022
ZipRecruitersimulation

K-Group Digit-Sum Compression

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this ZipRecruiter OA, reported in December 2022, is treating the group sums as single digits. They aren't. A group sum of 10 or 14 becomes two characters, so the string can stay long or even grow. K-Group Digit-Sum Compression is a simulation problem dressed up with a hash-table hint. You split, sum, concatenate, and repeat until the length is at most k. If you blank on the loop details during the live assessment, StealthCoder is the invisible safety net that reads the problem and hands you a working solution.

The problem

While digits.length > k, split it into consecutive groups of length k, allowing a shorter final group. Replace each group by its decimal digit sum and concatenate the replacements.
Return the first string whose length is at most k.

Function
compressDigitGroups(digits: String, k: int) → String

Examples
Example 1
digits = "1111122222"
k = 3
return = "132"
Repeated group-sum passes end at 132.
Example 2
digits = "1111122222"
k = 5
return = "510"
The two length-five groups sum to 5 and 10, producing 510.

Constraints
1 <= digits.length <= 100000
2 <= k <= 100000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core is a loop. While the string length is greater than k, walk it in chunks of k, add up the digit values in each chunk, convert each sum to a string, and join them. The last chunk can be shorter, and that's fine. The pitfall is the join. Use a list of string pieces and join once per pass, never repeated string concatenation, or you'll blow past the time budget with up to 100000 digits. Sums can be multi-digit, as example 2 shows with 510. Don't pad or truncate them. Each pass shrinks the string roughly by a factor of k when sums are small, and k is at least 2, so passes stay few. Edge case: if the length is already at most k, return the input untouched. StealthCoder is the hedge if you freeze mid-assessment, but the loop above is the whole answer.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill K-Group Digit-Sum Compression cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

K-Group Digit-Sum Compression FAQ

What's the trick in K-Group Digit-Sum Compression?+

There's no clever trick, it's careful simulation. Chunk the string by k, sum each chunk, write the sum as a full decimal string (it can be two or three characters), join, and repeat. The trap is assuming each group collapses to one digit. Example 2 gives 510, which proves it doesn't.

How hard is this ZipRecruiter OA question really?+

Easy to medium. The logic is short, but first attempts fail on multi-digit sums and slow string building. If you handle both, it's a quick pass. Most of the risk is in small implementation details, not in the algorithm itself.

Can the string grow instead of shrink during a pass?+

Yes, in principle, since a sum like 18 takes two characters. But with k at least 2, each group of k digits is replaced by at most a few characters, so the length drops over passes. Still, write the loop on the length condition, not on a fixed pass count.

How do I keep it fast for 100000 digits?+

Build each pass with a list of pieces and join once. Compute each group sum in a single scan using the digit value of each character. Total work is roughly linear in the starting length, since the string shrinks quickly each pass.

How should I prepare for this in 48 hours?+

Write the function from scratch twice. Test it on both examples, then on a length-1 input, a length equal to k, and a final short group. Check that sums of 10 or more stay as full numbers. That covers nearly every way this problem fails.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it