FastPrepFit Beta Parameters by Maximum Likelihood
Problems/Fit Beta Parameters by Maximum Likelihood

Fit Beta Parameters by Maximum Likelihood

Scale AI logoScale AI● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Scale AI new-grad onsite interview, in the final ML-fundamentals round. The report asks how data can estimate the parameters of a Beta distribution by maximum likelihood, and it asks for code that iterates. It does not give the dataset, the solver, the starting values, the stopping rule or the outputs. We fixed the data range to [0,1] and set limits on the values and their spread. The goal is the likelihood of the two shape parameters, using floating-point numbers. We chose the numerical method. The earlier phone simulation and other candidates' plot and KS tasks are separate. Our version is about 65% the same as the reported question.

Fit a Beta(alpha,beta) distribution to the observations in samples. The distribution lives on [0,1]: its location is 0 and its scale is 1. Only the two shape parameters are unknown, and both must be positive.

Find them by maximum likelihood, using an iterative method on the actual data. Return [alpha,beta] at the one finite point where the likelihood is highest, to the precision given below. A value that appears several times counts several times. The order of the samples does not change the answer.

The mean log-likelihood is

L(a,b) = logGamma(a+b) - logGamma(a) - logGamma(b)
       + (a-1) * mean(log(x)) + (b-1) * mean(log(1-x)).

Maximize it over a > 0 and b > 0 together. Write the iteration yourself with basic arithmetic and the standard math functions. You do not need a statistics-fitting library. You may start from the method-of-moments estimates, but they are not the answer. Running a fixed number of updates is not enough unless it really reaches the required precision.

Each returned value is accepted if its error is at most 1e-6 * max(1, abs(expected)). Do not round to a fixed number of decimal places.

Function

fitBetaParameters(samples: double[]) → double[]

Examples

Example 1

samples = [0.25,0.75]return = [1.9538947266061,1.9538947266061]

The two observations sit evenly on both sides of the middle, so alpha and beta come out equal. The method-of-moments estimate is not the likelihood maximum here. The values shown are approximate likelihood estimates, computed independently from these observations.

Example 2

samples = [0.01,0.02,0.05,0.1,0.2,0.3]return = [0.89734372204648,7.0711783149515]

The fit uses the two log averages from the formula above, taken over the actual samples. Here an iterative likelihood fit gives a different result from the method of moments. The values shown are approximate likelihood estimates, computed independently from these observations.

Example 3

samples = [0.01,0.99]return = [0.24418732507043,0.24418732507043]

Both ends of the allowed range are valid inputs. Here both shape estimates are below 1, which is why the rule that they must be positive matters. The values shown are approximate likelihood estimates, computed independently from these observations.

Constraints

  • 2 <= samples.length <= 2000
  • Every observation is a finite number in [0.01,0.99], and both ends of that range are allowed.
  • The population variance sum((x-mean)^2)/n is at least 0.001, where n is the number of samples. Together, these limits rule out samples that are all equal or almost equal, and values at the ends 0 and 1.
  • Location and scale stay fixed as stated above. You estimate only the two positive shape parameters. Use double-precision arithmetic.

More Scale AI Onsite Interview questions

  • Task Scheduler with DependenciesONSITE INTERVIEW · Seen Jul 2026
  • Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
  • Format and Validate a Model ResponseONSITE INTERVIEW · Seen Apr 2026
  • Stateful Neuron Matrix UpdateONSITE INTERVIEW · Seen Apr 2026
  • Clock Hand Angle with Subsecond PrecisionONSITE INTERVIEW · Seen Dec 2025
  • Four-Player Matching Card GameONSITE INTERVIEW · Seen Feb 2025
  • Rotate an Array to the RightONSITE INTERVIEW · Seen Oct 2024
  • Rich-Text Segment Normalization and Bold ToggleONSITE INTERVIEW · Seen Apr 2024
  • Minimum Distance Matching in a ForestPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2024
  • Shortest Distance Between Two NodesONSITE INTERVIEW · Seen Jan 2024

Similar questions at other companies

  • Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tensor-Parallel MLP GradientsOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • Deterministic K-Means AssignmentsMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Vectorized K-Means AssignmentsSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
  • Fixed-Round K-Means AssignmentsNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Confusing Bib NumbersVerily · ONSITE INTERVIEW
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Plus OneDruva · ONSITE INTERVIEW

Interview reports that mention this question

  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad ML Research Phone Screen: 1 Experience
  • Scale AI New Grad MLE Beta-Fit Phone Screen: 1 Experience
  • Scale AI New Grad ML Research Take-Home and Screen: 1 Experience

Scale AI interview experiences

  • Scale AI OA: What It Tests (2026)
  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public double[] fitBetaParameters(double[] samples) {
        // write your code here
    }
}
Checking account…