My requirements are as follows:
Input: one array of integers (the value will be only 0/1) and an integer z
Process: detecting all indexes of invalid zeros
Invalid zero is a zero belonging to run 0s whose length is greater than or equal to z
Output: ArrayList containing all invalid zeros indexes
Example:
input: Data: 1,0,0,0,1,1,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,1
ζ : 2
output: 2,3,4,17,18
==============================================>
I am using the following algorithm and want to know if there is a better way to do this?
Algorithm: verification (A [1 ... n], ζ)
Counter ⇐ 0
For i ⇐ 1 to n do
if A[i] == 0 then
counter ⇐ counter +1
if i == n and counter >= ζ then
for j ⇐ (n-counter) to n do
R.add(j)
else
if counter >= ζ
for j ⇐ (i-counter-1) to (i-1) do
R.add(j)
counter ⇐ 0
return R
thank