Given a 0 - 1string, return the number of substrings that have the same number of consecutive 0's and 1's.
Example1:
input:
110001100011010100001
output:
12
Explanation:
There are total 12 substrings that have the same number of consecutive 0's and 1's:
1100, 0011, 01, 1100, 01, 0011, 10, 01, 10, 01, 10, 01
Example2:
Input:
01010
Output:
4
Explanation:
There are 4 substrings that have the same number of consecutive 0's and 1's:
01, 10, 01, 10
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.