Repeated gene blocks

Write codeEasy16 min

Your task

A gene sequencer writes its calls as one long code string of uppercase letters. The calibration report slides a window of fixed width along that code, one character at a time, and flags any window whose exact contents already appeared at an earlier position, since a repeated block that size usually means the instrument latched. Given the code and the block width, return every distinct block that appears two or more times, sorted in ascending order by ordinary string comparison. List each repeated block once, no matter how many times it shows up. Return an empty list when the width is zero or negative, or wider than the code itself. Windows overlap: in AAAA a width of 2 yields the blocks AA, AA and AA, so AA is repeated.

Examples

repeated_block_codes(code: str, block: int) -> list[str]
Example 1
Inputrepeated_block_codes("ACGTACGTTT", 4)
Output["ACGT"]
Example 2
Inputrepeated_block_codes("ACGTACGTACGT", 3)
Output["ACG", "CGT", "GTA", "TAC"]
Example 3
Inputrepeated_block_codes("ABCDEF", 2)
Output[]