Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-263

Sample Size for an Eval Rate

Problem

Return the required sample size ceiling for estimating a rate p within absolute error using critical value z: ceil(z^2 * p * (1 - p) / error^2). Return 0 when p is not strictly between 0 and 1, or when error or z is non-positive.

Test cases

case 1
in: [0.5,0.05,1.96]
expected: 385
case 2
in: [0.8,0.02,2.576]
expected: 2655
case 3
in: [0.5,0,1.96]
expected: 0
case 4
in: [0,0.05,1.96]
expected: 0
Starter codePython
import math
def eval_sample_size(p, error, z):
    # Your code here
    pass

4 test cases · run your code against them in the editor