Maximum likelihood estimator (probability density function given by intervals) Let $\vartheta \in (0,1)$. Let $X_1,\ldots,X_n$ be a simple random sample with probability density function $f_\vartheta$,
$$\begin{align}f_{\vartheta}(x)=\begin{cases}1-\vartheta & \text{if} & -1<x<\frac{1}{2}\\ \vartheta & \text{if} & -\frac{1}{2}<x<\frac{1}{2}\\ 1-\vartheta & \text{if} & \frac{1}{2}<x < 1 \end{cases} \end{align}$$
I need to calculate $T$, maximum likelihood estimator of $\vartheta$.
I have: $${\bf f}_{\vartheta}(X_1=x_1,\ldots,X_n=x_n)=\displaystyle\prod_{i=1}^n f_\vartheta(x_i)=\prod_{i=1}^n \left[\vartheta I_A(x_i)+(1-\vartheta)I_B(x_i)\right]\\ \text{with}\; A =(-\frac12,\frac12),\; B=(-1,\frac12)\cup(\frac12,1) ~.$$
I need $\dfrac{\partial\,{\bf f}_\vartheta}{\partial \vartheta}=0$, but to do this I must write ${\bf f}_\vartheta$ in a convenient form. Thank you.

The parameter $\theta$ can be interpreted as the probability of a realization of the random variable $X$ to land in the interval $(-1/2,1/2)$. We expect that the MLE must be the number of events that landed in the above interval over the total number of events. In notation,
$$S=\{k\in\{1,...,n\}|x_k\in (-1/2,1/2)\}$$
$$N_A=|S|~,~ N_B=n-N_A$$
By multiplying out the likelihood above, we see that it is a discontinuous function in $\mathbb{R}^n$ with $2^n$ regions. We note however that many of these regions have the same likelihood function and therefore admit the same minimizer:
$${\bf f}_{\vartheta}(X_1=x_1,\ldots,X_n=x_n)=\vartheta^{N_A}(1-\theta)^{n-N_A}~~\text{, if} ~~~|S|=N_A\\N_A\in\{0,1,...,n\}$$
Therefore the MLE depends on the $x_i$'s only through the cardinality of the set of events in $(-1/2,1/2)$ and can be found to be via logarithmic differentiation to be
$$\hat\theta(x_1,.., x_n)=\frac{1}{n}\sum_{i=1}^n\mathbb{I}_{-1/2\leq x_i\leq 1/2}=\frac{N_A}{n}$$
