REFERENCE
correct in out
slow solution.
Code to check understanding of solution.