solution algorithm