i has the colour beads[i] (a letter), and taking it off the string costs effort[i] seconds.
You want no two neighbouring beads to share a colour. To get there you may remove any beads; the remaining ones close up, so the beads on either side of a removed one become neighbours.
Return the smallest total time needed to achieve this.beads="rggbg", effort=[2, 5, 3, 1, 4] → 3
Two g beads sit side by side at positions 1 and 2. Removing the second one is cheaper: 3 seconds.
beads="bbbab", effort=[4, 1, 6, 2, 2] → 5
The string starts with three b beads in a row: keep the costliest one (6) and remove the others for 4 + 1 = 5.
beads="abc", effort=[7, 7, 7] → 0
No two neighbours share a colour, so nothing has to go.
beads consists of lowercase English lettersbeads="rggbg", effort=[2, 5, 3, 1, 4]
3
Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.