Solution for Algorithms problems