# Best possible distribution for solving maximum-likelihood for a staircase data?

I have $n$ iid sample data $x_1,x_2,x_3..., x_n$ from a probability distribution function . The sample density is defined over $[0,1]$ and is of the form:

$$f(x) = \left\{\matrix{a, & x\in\left[0,\frac{1}{2}\right)\\b, & x\in \left[\frac{1}{2},1\right]}\right.$$where $a$ and $b$ are constants. The question is to solve for $a$ and $b$.

The approach I thought of it is to convert the problem to maximum-likelihood estimate. The sample density data looks like step function, which distribution would you suggest for parameterization of maximum likelihood problem?

Because $f$ is a density, we must have $a+b=2$.
Let $n'$ denote the number of samples in the interval $[0,1/2)$. The log likelihood is \begin{align} \log \prod_{i=1}^n f(x_i) &= \sum_{i=1}^n \log f(x_i) \\ &= n'\log(a) + (n-n')\log(b) \\ &= n' \log(a) + (n-n') \log (2-a). \end{align}
Taking the derivative with respect to $a$ and setting it equal to zero gives $$\frac{n'}{a} - \frac{n-n'}{2-a}=0,$$ so the maximum likelihood estimate for $a$ is $\frac{2n'}{n}$. Then the maximum likelihood estimate for $b$ is $\frac{2(n-n')}{n}$.