Linear time solution to a puzzle posed to me by Kris Jenkins