Extending a $k$-lipschitz function 
Given $f: Y\subset\mathbb{R}\to \mathbb{R}$ a $k$-lipschitz function, (i.e $|f(x)-f(y)|\leq k|x-y|$ for any $x,y\in Y$) I need to prove the existence of a $k$-lipschitz function $g:\mathbb{R}\to \mathbb{R}$ such that $g|_Y=f$.

My answer when $f$ is bounded is considering $$g(x)=\inf_{y\in Y}\{f(y)+k|x-y|\}.$$
Is it correct?. How do you find $g$ when $f$ is not bounded?.
 A: An alternate explicit construction:
First, you can continuously extend to the closure $\bar{Y}$ using the Lipschitz condition. 
Then, since $\bar{Y}$ is closed, for every $x\in \mathbb{R}\setminus \bar{Y}$ one can find $x_- = \max \bar{Y}\cap \{ y < x\}$ and $x_+ = \min \bar{Y}\cap \{y > x\}$. Then just linearly interpolate: 
$$ g(x) = f(x_-) + \frac{f(x_+) - f(x_-)}{x_+ - x_-} (x - x_-) $$

But let me explain Leonid Kovalev's comment. Notice that fixing some arbitrary $x' \in Y$, we have that for any $x\in\mathbb{R}$ now chosen to be fixed
$$ f(y) - f(x') + k|x-y| \geq f(y) -  f(x') + k|x' - y| - k|x-x'| $$
from triangle inequality. But using the $k$ lipschitz property you have that 
$$ f(y) - f(x') + k|x' - y| \geq 0 $$
so the expression
$$ f(y) - f(x') + k|x-y| \geq -k|x-x'| $$
where the right hand side is independent of $y$. Or, in other words
$$ f(y) + k|x-y| \geq f(x') - k|x-x'| $$
so the expression you want to take the infimum of (in $y\in Y$) is bounded from below by some constant, and hence the infimum exists. 
A: We have the following theorem:
Suppose that $||x_i-x_j||\geq ||x'_i-x'_j||$. Then, for all $r_i \geq 0$, we have that, if $\cap_i B(x_i,r_i)\neq \varnothing$, then $\cap_i B(x'_i,r_i)\neq \varnothing$.
Ok. Now, let's suppose that $f$ is 1-Lipchitz on a subset $\{x_i\}_i=Y\subset \mathbb{R}^n$. Let's see that we can extend $f$ to a point $a\notin Y$. Note that $a\in \cap_i B(x_i,||x_i-a||)$. Note also that $||f(x_i)-f(x_j)||\leq ||x_i-x_j||$. Then, for the theorem, there exist a point $u \in \cap_i B(f(x_i),||x_i-a||)$. Denote $f(a)=u$. It follows that $||f(a)-f(x_i)||\leq ||a-x_i||$ for all $x_i \in Y$. So we can extend $f$ to a point and preserving Lipchitz condition.
Now, use Zorn's lemma on $\mathcal{F}= \{(g,B)|\text{ } A\subset B \text{ and } g|_A=f \text{ and } g \text{ is 1- Lipchitz} \}$ with the preorder $(g,B)\leq (h,C)$ iff $B\subset C$ and $h|_B=g$. You are going to  get a maximal element $(M,F)$ such that $F$ is 1-Lipchitz and $F|_Y=f$. If $M \neq \mathbb{R}$, then you can extenf $F$ to a point by the previous construction, but $F$ is maximal and you get a contradiction. Then $M=\mathbb{R}$.
