Let $J$ be a finite subinterval of the real line and $f:J\rightarrow\mathbb{R}$ a simple function taking on values $c_1,...,c_n$. The function $f$ is called a step function if $f^{-1}(c_i)$ is a finite union of intervals for each $i$. Given a simple function $s:J\rightarrow\mathbb{R}$ and a positive number $\varepsilon$, show that there exists a step function $f$ such that $$\int_J|s-f|\,d\mu_L<\varepsilon$$ Hint: Show that, if $A$ is a measurable subset of $J$, there exists a finite union of intervals $B$ such that $d(A,B)=\mu(S(A,B))<\varepsilon$. Now prove the above for $s=1_A$. Proceed.
I'm not sure how to do this problem, even with the hint. I don't know how to show the statement in the hint or how to get from there to the question itself.
Assuming that we are talking about the Lebesgue measure, let us use the letter $\lambda$, we remind its definition, for every $\lambda-$measurable set $A$: $$\lambda(A):=\inf\left\{\sum_{i=1}^\infty l(I_i):I_i\text{ is an open interval, }i=1,2,\dots,\ A\subseteq\bigcup_{i=1}^\infty I_i\right\}$$ where $l(I)$ is the length of an iterval $I$ - so, if the interval has boundaries $a,b\in\mathbb{R}$ with $a<b$ then $l(I)=b-a$.
Note now that, if $I_i$, $i=1,2,\dots$ are all open intervals, and $I=\bigcup_i I_i$ is their union, we can see that the following sequence of sets: $$\begin{align*} B_1&=I_1\\ B_2&=I_1\setminus B_1\\ &\vdots\\ B_n&=I_n\setminus\bigcup_{i=1}^{n-1}B_i\\ &\vdots \end{align*}$$ It is clear that $B_k\cap B_l=\varnothing$ for every $k,l\in\mathbb{N}$ and that: $$\bigcup_{i=1}^\infty B_i=\bigcup_{i=1}^\infty I_i$$ Moreover, for every $k=1,2,\dots$, we can see, from the definition of $B_k$, that $B_k$ is a finite union of (not necessarily open) intervals - it is an open interval "minus" a finite number of open intervals. Also, note that: $$\sum_{i=1}^\infty l(I_i)\geq\lambda\left(\bigcup_{i=1}^\infty I_i\right)=\lambda\left(\bigcup_{i=1}^\infty B_i\right)=\sum_{i=1}^\infty\lambda(B_i)=\sum_{i=1}^\infty l(B_i)\tag{$\star$}$$ Taking infima to $(\star)$, we can easily see that: $$\lambda(A)=\inf\left\{\sum_{i=1}^\infty l(B_i):B_i\text{ is a finite union of intrv., }B_i\cap B_j=\varnothing,\ \forall\ i,j\in\mathbb{N},\ A\subseteq\bigcup_{i=1}^\infty B_i\right\}$$ Can you now prove the hint, after this sub-hint? I'll come up with a complete solution, later on, if you cannot get it till the end! :)
Edit: Note at first that, if $\lambda(A)=0$, then is is easy to find such a set - e.g. a subinterval of $J$ with length lesser than $\epsilon$. So let us assume that $\lambda(A)>0$.
Let $\epsilon>0$. By definition of the Lebesgue measure - the "alternative" definition - we have that there exists a sequence $B_n$, where $B_n$ is a finite union of intervals, $B_k\cap B_l=\varnothing$, $\forall\ k,l=1,2,\dots$ such that: $$\sum_{n=1}^\infty l(B_n)-\lambda(A)<\frac{\epsilon}{2}$$ Also, since $B_n$ are not intersecting, we have that: $$\lambda\left(\bigcup_{n=1}^\infty B_n\setminus A\right)<\frac{\epsilon}{2}$$ Consider now the set sequence $$S_n=\bigcup_{i=1}^nB_i\setminus A$$ It is clear that $S_n$ is increasing and, hence: $$\lim_{n\to\infty}\lambda(S_n)=\lambda\left(\bigcup_{i=1}^\infty B_i\setminus A\right)$$
So, for every $n\in\mathbb{N}$ $$\lambda(S_n)<\frac{\epsilon}{2}$$
Also, note that, if $$a_n=\lambda\left(A\setminus\bigcup_{i=1}^nB_i\right)$$ then $a_n$ is decreasing and, since it is bounded, it is convergent. Since $a_1<\infty$, we have that: $$\lim_{n\to\infty}a_n=\lambda\left(A\setminus\bigcup_{i=1}^\infty B_i\right)=\lambda(\varnothing)=0$$ So, there exists a $n_0\in\mathbb{N}$ such that, for every $n\geq n_0$: $$0\leq a_{n}<\frac{\epsilon}{2}\Rightarrow0\leq\lambda\left(A\setminus\bigcup_{i=1}^n B_i\right)<\frac{\epsilon}{2}$$ Now, let $$B=\bigcup_{i=1}^{n_0}B_i$$ so: $$\lambda(S(A,B))=\lambda(A\setminus B)+\lambda(B\setminus A)<\frac{\epsilon}{2}+\frac{\epsilon}{2}=\epsilon$$ Since $B_i$ are all finite unions of intervals, it is obvious that $B$ is also a finite union of intervals.
Now, if $s$ is a simple function with values $c_1,\dots,c_n$, and $A_i=s^{-1}(\{c_i\})$ for every $i=1,2,\dots,n$, then: $$s(x)=\sum_{i=1}^nc_i1_{A_i}(x)$$ Due to the triangular inequality and the linearity of Lebesgue's integral, we shall prove the requested only in the case when $s=1_A$, where $A$ is some measurable set - note that a set $A$ is measurable if and only if $1_A$ is a measurable function.
Let $\epsilon>0$. If $s=1_A$, and $s$ is measurable, then $A$ is also measurable. So, there exists a union of intervals $B$, such that: $$\lambda(S(A,B))<\epsilon$$ Let $f=1_B$. Note now that, on every $x\in A\cap B$ we have $s=f=1\Rightarrow s-f=0$. On every $x\in J\setminus(A\cup B)$ we have that $s=f=0\Rightarrow s-f=0$. Now, on every $x\in S(A,B)$ we have that $|s-f|=1$ (explain why), so $$|s-f|=!_{S(A,B)}$$ Now it follows that: $$\int_J|s-f|d\lambda=\int_J1_{S(A,B)}d\lambda=\int_{S(A,B)}d\lambda=\lambda(S(A,B))<\epsilon$$.
Try to complete this proof - all the details missing. Ask whatever you may need! :)