Question: Problem 3. Consider a sequence of n brackets, where each bracket is either opening (namely [) or closing (]). The sequence is legal if, intuitively,

Problem 3. Consider a sequence of n brackets, where each bracket is either opening (namely "[") or closing ("]"). The sequence is legal if, intuitively, every opening bracket finds its closing counterpart. For example, [[]]] is legal but [[]]] is not. Formally, a legal sequence is such that, one can continuously remove two adjacent brackets [] until all the brackets have disappeared. Suppose that the sequence is stored in an array of length n, where each bracket is stored in a cell. Give an algorithm to check whether the sequence is legal in O(n) time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
