2
public int minOperations(String s) {3
int count0 = 0; // changes required when the string starts from 04
int count1 = 0; // changes required when the string starts from 16
for (int i = 0; i < s.length(); i++) {8
// string starts with 1 => all chars at even places should be 1 and that at odd places should10
if ((i % 2 == 0 && s.charAt(i) == '0') || (i % 2 != 0 && s.charAt(i) == '1')) count1++;12
// string starts with 0 => all chars at even places should be 0 and that at odd places should14
else if ((i % 2 == 0 && s.charAt(i) == '1') || (i % 2 != 0 && s.charAt(i) == '0')) count0++;17
// return minimum of the two18
return Math.min(count0, count1);