Code for common algorithm problems