build poem finding greedy algorithm