Count payloads with sync once
A frame format reserves a sync word so a receiver can tell where a frame begins. A payload is usable only when the sync word turns up in it exactly once, since no appearance leaves the receiver nothing to lock onto and a second appearance lets it cut the frame in the wrong place. Payloads are exactly size characters long and are built from the characters of alphabet, which are distinct and need not cover every character of sync. Given alphabet, size and sync, return how many payloads hold sync exactly once, where appearances that overlap count separately, so aa turns up twice inside aaa. The sync word is never empty, and a negative size describes no payload at all. Totals grow fast, so return the answer modulo 1000000007.
single_sync_payload_count(alphabet: str, size: int, sync: str) → int["ab",3,"ab"]out4["ab",4,"aa"]out5["abc",5,"abc"]out27State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
["ab",3,"ab"]4not run yetsample["ab",4,"aa"]5not run yetsample["abc",5,"abc"]27not run yetsample