Reported September 2026
Salesforcestring

Run-Length String Compression

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

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

The detail that trips people on this Salesforce OA, reported in September 2026, is the 12 in "ab12". Counts aren't single digits, and a group of one gets no number at all. It's a string run-length compression problem, and it's easier than it looks if you stay calm. Most misses come from off-by-one slips at the end of the string or from appending "1" where the rules say not to. If you blank under the timer, StealthCoder is a safety net that runs invisibly during the live assessment and can hand you the clean loop. Know the shape first, though.

The problem

Given a string s, compress each maximal group of consecutive equal characters.
Append the group's character once.
If the group contains more than one character, append its full length in base 10.
If the group contains exactly one character, do not append a count.
Return the compressed string.

Function
compressString(s: String) → String

Examples
Example 1
s = "aaaabeee"
return = "a4be3"
The groups are aaaa, b, and eee. Their encodings are a4, b, and e3.
Example 2
s = "a"
return = "a"
The only group has length 1, so no count is appended.
Example 3
s = "abbbbbbbbbbbb"
return = "ab12"
The first group contributes a. The following group contains 12 copies of b, so it contributes b12.

Constraints
1 <= s.length <= 2000
s contains letters, digits, or symbols.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a single pass with a run counter. Walk the string, and whenever the next character differs from the current one (or you hit the end), flush the group: append the character, then append the count only if it's greater than 1. Convert the count with str(count), never a single character cast, because 12 must become "12". The classic pitfall is forgetting to flush the last group after the loop ends. The second is writing count 1 for singletons, which breaks Example 2. Third, digits in the input are valid characters, so don't treat them specially. Use a list or StringBuilder and join once instead of concatenating in a loop. With length up to 2000, O(n) is trivially fine. If you freeze on the boundary handling during the live OA, StealthCoder can give you the loop as a backup.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Run-Length String 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as string compression. If you have time before the OA, drill that.

⏵ The honest play

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

Salesforce reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Run-Length String Compression FAQ

How hard is the Salesforce run-length compression problem really?+

Easy. It's a single pass over a string with a counter. The difficulty is purely in edge cases: the final group, singleton groups with no count, and multi-digit counts like 12. If you've written run-length encoding once, you can finish this quickly.

What's the trick to getting it right the first time?+

Flush a group whenever the next character differs or you reach the end. Append the character, then append the count only if it's above 1. Use str(count) so multi-digit lengths work. Handle the last group either with a sentinel or a post-loop flush.

Do digits in the input break the compression?+

No. The input can contain letters, digits, or symbols, but you only compare characters for equality. A run of '1' characters becomes '1' followed by the count, like "15" for... a single '1' repeated 5 times. You're not decoding, so there's no ambiguity to handle.

Is string compression still asked in OAs?+

Yes. It was reported for Salesforce in September 2026. Run-length style string questions are a staple because they test boundaries and clean iteration, not clever algorithms. Expect variations like decoding or in-place compression.

How do I prepare in 48 hours?+

Write this one from scratch twice without looking. Test it on a single character, all identical characters, all distinct characters, and a run of 10 or more. Then practice the two-pointer version where you jump i to the end of each group. That covers nearly every variant.

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

OA at Salesforce?
Invisible during screen share
Get it