colors (colours are positive integers). The scarf is properly striped when two patterns strictly take turns:
- colors[i - 2] == colors[i] for every 2 ≤ i < n;
- colors[i - 1] != colors[i] for every 1 ≤ i < n.
In one operation you can repaint any stripe with any positive colour. Return the minimum number of repaints that makes the scarf properly striped.colors=[4, 2, 4, 4, 1, 2] → 2
Keep 4 on even places and 2 on odd ones: repaint stripe 3 (4 → 2) and stripe 4 (1 → 4). 2 repaints in total.
colors=[7, 7, 7, 7] → 2
Neighbouring stripes may not share a colour, so the stripes at odd places have to be repainted with another colour: 2 stripes.
colors=[3, 5, 3, 5, 3] → 0
colors=[4, 2, 4, 4, 1, 2]
2
Run checks the first 3 tests in your browser. Submit checks all 135 tests on the server, hidden ones included.