Added a condition for start_index <=max_bernoulli && start_index+no_bernoullis+b2n>=max_bernoulli