Skip to content

Instantly share code, notes, and snippets.

@rjchee
Created December 29, 2025 08:40
Show Gist options
  • Select an option

  • Save rjchee/23ec59f67c6835f3c58a57dbf83837fa to your computer and use it in GitHub Desktop.

Select an option

Save rjchee/23ec59f67c6835f3c58a57dbf83837fa to your computer and use it in GitHub Desktop.
for cassidoo's #437 interview question
import re
def replaceRepeats(s: str, n: int) -> str:
return re.sub(f"{n}+", lambda m: str(len(m[0])), s)
print(f"{replaceRepeats('1234500362000440', 0)=}")
print(f"{replaceRepeats('000000000000', 0)=}")
print(f"{replaceRepeats('123456789', 1)=}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment