DP and linear version for longest substring without repeat, zigzag conversion