Amazon·Software Engineer·Onsite - Coding / Algorithms
- You're given a string containing '0', '1', and '!' characters. Each '!' can be independently replaced with '0' or '1'. After substitution, every '10' subsequence contributes x errors and every '01' subsequence contributes y errors. Return the total error count modulo 10^9 + 7. (Variant: minimize or maximize the total.)
“My first instinct was to try all combinations of replacements which is obviously wrong the moment you think about input size.”