You are given an integer array nums of length n.
For each index i, determine:
nums[i]
has appeared in any index
< i
.
nums[i]
appears in any index
> i
.
Construct two binary strings of length n:
left[i] = '1'
if
nums[i]
appears in
nums[0..i-1]
, else
'0'
.
right[i] = '1'
if
nums[i]
appears in
nums[i+1..n-1]
, else
'0'
.
Return [left, right].
Example
nums = [5, 1, 5, 2, 1]
left = "00101"
(the second
5
and the second
1
have appeared on the left)
right = "10110"
(the first
5
and first
1
appear again on the right)
Constraints (typical): 1 ≤ n ≤ 2e5, nums[i] fits in 32-bit signed integer.
You are given a binary string s (characters are only '0' and '1').
Each second, all occurrences of substring "01" are replaced simultaneously with "10".
Repeat this process until the string contains no "01".
Return the number of seconds required.
Example
s = "010110"
?
(compute the number of synchronous steps until no "01" remains)
Notes: A direct step-by-step simulation can be too slow for large strings; the intended solution should account for interactions where multiple '1's can “block” each other.
Constraints (typical): 1 ≤ |s| ≤ 2e5.