DevPrep

All topics › Real interview tasks

String of 0, 1 and !: minimum error cost

Senior PRO

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

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store