Test the Hypothesis
Learn this problemProblem statement
Given two arrays and a confidence level, determine whether the means of these series are significantly different using a two-tailed t-test. Additionally, output the magnitude by which the hypothesis passes or fails.
The magnitude is defined as the minimum absolute difference between the computed t-statistic and the t-statistic at the confidence level at the two tails.
Return an array with two values. The first element is "Yes" if the means are significantly different, or "No" if they are not. The second element is the magnitude rounded to 2 decimals.
For FastPrep's multi-language runner, return both values as strings, with the magnitude formatted to exactly two decimal places.
Source note: The screenshot has a tiny rounding/number typo in the samples, so FastPrep uses the mathematically consistent values while keeping the same t-test rules and source image visible below.
Function
testHypothesis(n: int, x: float[], y: float[], confidence_level: float) → String[]Complete the function testHypothesis with the following parameters:
| Parameter | Type | Description |
|---|---|---|
n | int | the number of data points |
x[n] | float | an array of data points |
y[n] | float | another array of data points |
confidence_level | float | the confidence level to test the hypothesis |
Examples
Example 1
n = 4x = [4.461, 7.757, 17.317, 4.151]y = [8.911, 12.68, -10.593, 17.048]confidence_level = 0.95return = ["No", "2.47"]Performing a t-test at the 95% confidence level shows that the means are not significantly different, and the magnitude by which the null hypothesis passes is 2.47.
Example 2
n = 10x = [0.878, 2.817, 0.121, -0.945, -0.055, -1.456, 0.35, -1.478, -1.687, -1.889]y = [1.142, -0.492, -0.988, -0.729, -0.846, -0.157, 0.5, 1.188, -1.075, -0.189]confidence_level = 0.95return = ["No", "1.82"]Performing a t-test at the 95% confidence level shows that the means are not significantly different, and the magnitude by which the null hypothesis passes is 1.82.