My implementation for the popular interview code test