Given a string s of '(' and ')', return the length of the longest valid balanced substring using only O(1) extra space (two directional passes counting brackets). The input is JSON {s}.
Input: JSON {s}.
Output: Integer — the longest valid substring length.
Input: {"s":")()())"}
Output: 4
Explanation: '()()' has length 4.Input: {"s":"(()"}
Output: 2
Explanation: '()' has length 2.Input: {"s":""}
Output: 0
Explanation: Empty string.0<=|s|<=10^5