seq optimal algorithm