This two-part question evaluates combinatorial enumeration and subset-generation concepts for arrays alongside string parsing and parentheses-sequence validation for noisy input, measuring algorithm design, correctness, and complexity reasoning in array and string contexts.
You will solve two independent coding tasks.
You are given an integer array nums containing n distinct elements.
Return all possible subsets (the power set) of nums.
0
to
n
.
Example
Input:
nums = [1, 2, 3]
One valid output (order may differ):
[ [], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3] ]
Constraints
1 <= n <= 20
-10^9 <= nums[i] <= 10^9
nums[i]
are distinct.
You may return the result in any order.
You are given a string s that may contain:
'('
and
')'
, and
A string is considered parentheses-valid if, after ignoring all non-parenthesis characters, the remaining sequence of '(' and ')' is a valid parentheses sequence:
'('
has a corresponding closing parenthesis
')'
.
Implement a function that returns true if s is parentheses-valid, and false otherwise.
Examples
s = "a(b)c"
"()"
which is valid.
true
.
s = "(a(b)c"
"(()"
which is not valid.
false
.
s = "ab)c(d)e"
")()"
which is not valid.
false
.
Constraints
1 <= len(s) <= 10^5
s
may contain any printable ASCII characters.