Code for algorithm problems