1111. Maximum Nesting Depth of Two Valid Parentheses Strings Medium
1/**
2 * [1111] Maximum Nesting Depth of Two Valid Parentheses Strings
3 *
4 * A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and:
5 *
6 *
7 * It is the empty string, or
8 * It can be written as AB (A concatenated with B), where A and B are VPS's, or
9 * It can be written as (A), where A is a VPS.
10 *
11 *
12 * We can similarly define the nesting depth depth(S) of any VPS S as follows:
13 *
14 *
15 * depth("") = 0
16 * depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's
17 * depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
18 *
19 *
20 * For example, "", "()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.
21 *
22 *
23 *
24 * Given a VPS <font face="monospace">seq</font>, split it into two disjoint subsequences A and B, such that A and B are VPS's (and A.length + B.length = seq.length).
25 *
26 * Now choose any such A and B such that max(depth(A), depth(B)) is the minimum possible value.
27 *
28 * Return an answer array (of length seq.length) that encodes such a choice of A and B: answer[i] = 0 if seq[i] is part of A, else answer[i] = 1. Note that even though multiple answers may exist, you may return any of them.
29 *
30 * Example 1:
31 *
32 * Input: seq = "(()())"
33 * Output: [0,1,1,1,1,0]
34 *
35 * Example 2:
36 *
37 * Input: seq = "()(())()"
38 * Output: [0,0,0,1,1,0,1,1]
39 *
40 *
41 * Constraints:
42 *
43 * 1 <= seq.size <= 10000
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/
49// discuss: https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn max_depth_after_split(seq: String) -> Vec<i32> {
55 vec![]
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_1111() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.