\(f\) is a function. So is \(g\text{.}\) There is no problem with an element of the codomain not being the image of any input, and there is no problem with \(a\) from the codomain being the image of both 2 and 3 from the domain. We could use our two-line notation to write these as

\begin{equation*} f= \begin{pmatrix} 1 \amp 2 \amp 3 \amp 4 \\ d \amp a \amp c \amp b \end{pmatrix} \qquad g = \begin{pmatrix} 1 \amp 2 \amp 3 \amp 4 \\ d \amp a \amp a \amp b \end{pmatrix}\text{.} \end{equation*}

However, \(h\) is NOT a function. In fact, it fails for two reasons. First, the element 1 from the domain has not been mapped to any element from the codomain. Second, the element 2 from the domain has been mapped to more than one element from the codomain (\(a\) and \(c\)). Note that either one of these problems is enough to make a rule not a function. In general, neither of the following mappings are functions:

Three black dots in a row above and two white dots in a row below.  An arrow points from the left black dot to the left white dot and from the right black dot to the right white dot.
Three black dots in a row above and four white dots in a row below.  Two arrows point from the left black dot to each of the two left-most white dots.  Each of the other black dots have an arrow pointing down to the white dots below and slightly to the right of them.

It might also be helpful to think about how you would write the two-line notation for \(h\text{.}\) We would have something like:

\begin{equation*} h=\twoline{1 \amp 2 \amp 3 \amp 4}{\amp a,c? \amp d \amp b}\text{.} \end{equation*}

There is nothing under 1 (bad) and we needed to put more than one thing under 2 (very bad). With a rule that is actually a function, the two-line notation will always “work”.