You are given two independent coding tasks.
You have n courses labeled 0..n-1 and a list of prerequisite pairs prereq.
[a, b]
means: to take course
a
, you must finish course
b
first.
true
if it is possible to finish all
n
courses (i.e., there is no prerequisite cycle). Otherwise return
false
.
Input
n
prereq
where each element is
[a, b]
Output
Constraints (typical interview scale)
1 ≤ n ≤ 10^5
0 ≤ |prereq| ≤ 2*10^5
Given a string s consisting of lowercase letters and parentheses '(' and ')', remove the minimum number of parentheses so that the resulting string is valid.
A string is valid if:
')'
has a matching
'('
before it.
Return one valid string after performing the minimum removals.
Input
s
Output
Constraints (typical interview scale)
1 ≤ |s| ≤ 10^5
Notes