Advanced Algorithm Q.6