Show that $f \in L^{1}(X)$ if and only if $\sum_{n=1}^{\infty} n \mu(E_{n}) < \infty$. Let $(X,\mathcal{A}, \mu)$  a finite measure space. Also let $f: X \to \mathbb{R}$ and $$E_{n}=\lbrace x \in X \: | \: |f(x)| \in [n,n-1) \rbrace$$. Show that $f \in L^{1}(X)$ if and only if $\sum_{n=1}^{\infty} n \mu(E_{n}) < \infty$. More generally  $f \in L^{p}(X)$ for $p \in [1,\infty)$ if and only if $\sum_{n=1}^{\infty} n^{p} \mu(E_{n}) < \infty$. I have been trying to solve this problem since a couple of days but being honest I, frustrated since I can came with any idea or proof of this. So far I have been checking the analogue problem here
Prove that $f$ is integrable if and only if $\sum^\infty_{n=1} \mu(\{x \in X : f(x) \ge n\}) < \infty$
but still dont understand the proofs there as well there are other hypothesis going on there. Thanks for helping.

Well, the proof is exactly the same as for the other statement (in fact, the sums in question are equal). I'm assuming, by the way, that you meant $E_n=[n-1,n)$.
Basically, $f=\sum_{n=1}^{\infty} 1_{E_n} f,$ and clealy $1_{E_n} f$ lies between $n-1$ and $n$ when it's not equal to $0$. Hence, $1_{E_n}f\leq 1_{E_n}n$ and $1_{E_n}f \geq 1_{E_n} (n-1),$ and we get, by Monotone Convergence, that
$$
\int f\textrm{d}\mu=\sum_{n=1}^{\infty} \int f 1_{E_n}\textrm{d}\mu\leq \sum_{n=1}^{\infty} n \mu(E_n)
$$
and similarly,
$$
\int f\textrm{d}\mu\geq \sum_{n=1}^{\infty} (n-1)\mu(E_n)\geq \left(\sum_{n=1}^{\infty}n \mu(E_n)\right) -\mu(X),
$$
where we've used that $\mu(X)<\infty$ and that the $E_n$ are disjoint.
The statement follows. The general $L^p$ argument is similar.
