longest sequence grid problem