Question: Consider the following function for finding the second-to-last element of a list:

```
myButLast (x:xs) = if length xs > 1 then myButLast xs else x

```

This is an O(n^2) algorithm, because `length xs` is O(n) and is called O(n) times. What is the most elegant way to write this in Haskell such that `length` stops once it gets past 1, so that the algorithm is O(n)?

Answer: 
what about

```
myButLast []     = error "oho"
myButLast [x,_]  = x
myButLast (_:xs) = myButLast xs

```
Another zip-based solution, without exlicitly zipping. Throw in some safety for good measure.

```
import Data.Maybe

g :: Int -> [a] -> Maybe a
g i = (head <$>) . listToMaybe . reverse         -- quick'n'dirty safe-last
                 . getZipList . traverse ZipList 
                 . sequence [id, drop i] 

g  1 [1..10] => Just 9
g  3 [1..10] => Just 7
g 13 [1..10] => Nothing

```