Problems > Count the Transitions

Count the Transitions

Difficulty: 800 2000 ms 128 MB

strings

Count positions where a binary string switches between 0 and 1 (adjacent unequal characters).

Input: one line with a binary string.

Output: the number of transitions.

Constraints:

  • 1 ≤ |S| ≤ 105

Sample Tests

Input 1
00110
Output 1
2
Input 2
1111
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.