task1
task1
We
consider the string to be balanced if each < always appears before (i.e., to the
left of)
a corresponding > character (they do not need to be adjacent). Moreover, each <
and > act as a unique pair of symbols and neither symbol can be considered as part
of
any other pair of symbols. For example, the strings <<>>, <>, and <><> are
all balanced, but the strings >>, <<>, and ><>< are unbalanced.
Complete the balancedOrNot function in the editor below. It has the following
parameters:
The function must return an array of integers where each index i (0 ≤ i < n)
contains a 1 if expressions i is balanced or a 0 if it is not.
Input Format
The first line contains an integer, n, denoting the size of expressions.
Each line i of the n subsequent lines (where 0 ≤ i < n ) contains a string
describing expressions i.
The next line contains an integer, m, denoting the size of maxReplacements.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains a string
describing maxReplacementsi.
Constraints
1 ≤ n ≤ 102
1 ≤ length of expressionsi ≤ 105
0 ≤ maxReplacementsi ≤ 105
Output Format
The function must return an array of integers where each index i (0 ≤ i < n)
contains a 1 if expressionsi is balanced or a 0 if it is not.
Sample Input 0
2
<>>>
<>>>>
2
2
2
Sample Output 0
1
0
Explanation 0
We process expressions = ["<>>>", "<>>>>"] and maxReplacements = [2, 2] like so:
Sample Input 1
2
<>
<>><
2
1
0
Sample Output 1
1
0
Explanation 1
We process expressions = ["<>", "<>><"] and maxReplacements = [1, 0] like so: