Solution to Programming Challenge for EA interview