The key here is to see that counter can be incremented by maximum n times and the complexity of f depends upon counter.
Now if counter can contain maximum n,then it is not possible for f to have more than n complexity.
f can have one call taking n complexity ,or multiple calls whose combined complexity is n.
Consider that first we get x 1 and then 0 ,now f(x) will run till x,then we get y 1 followed by 0,now f(y) will run till y.
total elements x+y=n,so lop goes till n,
total time f executed =x+y
Min. f executes 0 and max. n.
--------------------------------------------------------------------------------------------------------------------
Also,note that if array contains all 1's then time would be thetha(n),and based on this we can reject A,B,D.