As reported: Goldman Sachs Analyst HackerRank OA (70 minutes, two mediums, 2025): string compression,
aaGGbbbc → 2a2G3b1c, with upper- and lower-case letters. "String compression" was also one of the two CoderPad problems in a GBM Transaction Banking loop (2026, both passed) and in an Analyst CoderPad (2025, corner cases covered with extra tests).
Compress s by replacing every maximal run of the same character with the run length followed by the character. Runs of length 1 are written too (1c). Letters are case-sensitive (a and A are different).
Example 1
s = "aaGGbbbc"
-> "2a2G3b1c"
Example 2
s = "abc"
-> "1a1b1c"
Constraints: 1 ≤ s.length ≤ 10^5; s contains English letters.
Code runner format: one JSON value per line: s. Implement compress(s); the harness prints the compressed string as JSON.