Algorithm Solution Code