So you have some vector that contains 1's and 0's, and the goal is to return a vector that gives the number of 0's between each one. for example:
Input = [0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0]
Output = [1 3 1 0 0 3 1 0 2]
My opinion is that the answers for this problem are wrong. The problem is asking for counting zeros between values 1. So for example for Input = [0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0] the correct Output is [3 1 0 0 3 1 0] and not [1 3 1 0 0 3 1 0 2]. Reasoning that there is no 1 at the beginning and at the end of the vector and so the beginning and end zeros should not be counted.
How about adding a test case in which vector x starts with a 1, such as x = [1 0 0 1 0] ? (Several of the submitted/approved solutions would give the answer as y = [0 2 1] instead of y = [2 1] . )
I was looking for this solution:
http://www.mathworks.de/matlabcentral/cody/problems/1678-count-consecutive-0-s-in-between-values-of-1/solutions/267945
but I was not precise enough with the regexp... ;-)
Nice Shot!!
Given two strings, find the maximum overlap
310 Solvers
246 Solvers
309 Solvers
How long is the longest prime diagonal?
283 Solvers
Flag largest magnitude swings as they occur
527 Solvers