O(n) in place to solve longest valid parentheses