1st and 2nd problems (Algorithms)