Problem 1678. Count consecutive 0's in between values of 1
Solution Stats
Problem Comments
-
4 Comments
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] . )
The starting or the trailing zeros in the array shouldn't be counted.
I think your first test case is wrong: when x = [1], then there are no pairs of consecutive ones, and the proper answer is y = [] rather than y = [0]. In contrast, y = [0] is correct when x = [1 1], where there are two ones that have no zeros in between.
Solution Comments
Show commentsProblem Recent Solvers330
Suggested Problems
-
2093 Solvers
-
287 Solvers
-
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
509 Solvers
-
401 Solvers
-
6202 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!