Code RoomCount payloads with sync once
HardPrep Room Coding #4937

Count payloads with sync once

CodingAlgorithms & data structuresSenior–Staff~40 min

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.

Implement
single_sync_payload_count(alphabet: str, size: int, sync: str) → int
Examples
in["ab",3,"ab"]out4
in["ab",4,"aa"]out5
in["abc",5,"abc"]out27
What a strong answer looks like

State 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.

0:00 of about 40 min
InputExpectedGot
["ab",3,"ab"]4not run yetsample
["ab",4,"aa"]5not run yetsample
["abc",5,"abc"]27not run yetsample