2017-09-18 09:16:14 -07:00
|
|
|
// Author: Rodney Shaghoulian
|
2018-07-27 16:45:56 -07:00
|
|
|
// Github: github.com/RodneyShag
|
|
|
|
|
// HackerRank: hackerrank.com/RodneyShag
|
2017-09-18 09:16:14 -07:00
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
// Idea: - For each 010, we can flip it to 011, and count that as one "step".
|
|
|
|
|
// - An easy way to count the number of steps is to change each 010 to 01 instead,
|
|
|
|
|
// and to compare the length of the resulting string with the original string
|
|
|
|
|
|
|
|
|
|
public class Solution {
|
|
|
|
|
static int minSteps(String B) {
|
|
|
|
|
return B.length() - B.replace("010","01").length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Scanner scan = new Scanner(System.in);
|
|
|
|
|
scan.nextInt(); // we don't need "n"
|
|
|
|
|
String B = scan.next();
|
|
|
|
|
scan.close();
|
|
|
|
|
|
|
|
|
|
System.out.println(minSteps(B));
|
|
|
|
|
}
|
|
|
|
|
}
|