String of 0, 1 and !: minimum error cost
Task
You are given a string of 0, 1 and ! (each ! can become 0 or 1) and numbers x, y. Every subsequence 01 (a zero before a one) costs x, every 10 costs y. Return the minimum total cost modulo 10⁹.
"01!!", x = 2, y = 3→ 6 (option0111: three01pairs × 2)."!!!!", x = 2, y = 5→ 0 (all the same — no pairs).- Length up to 50,000.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep