Last active
December 30, 2025 16:38
-
-
Save hyojjxipitug/e9eb26321038e4d8cfb38828e4fd98ab to your computer and use it in GitHub Desktop.
Answer to interview question from Cassidoo’s newsletter (12/29/25):
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def replaceRepeats(s, n): | |
| count = 0 | |
| output = '' | |
| for c in s: | |
| if c == str(n): | |
| count += 1 | |
| elif count > 0 and c != str(n): | |
| output += str(count) | |
| output += c | |
| count = 0 | |
| else: | |
| output += c | |
| if count > 0: | |
| output += str(count) | |
| return output | |
| assert replaceRepeats('1234500362000440', 0), '1234523623441' | |
| assert replaceRepeats('000000000000', 0), '12' | |
| assert replaceRepeats('123456789', 1), '123456789' | |
| print('Happy 2026 🥳🎉') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment