Skip to main content

Posts

Balanced Brackets

Balanced Brackets :- A bracket is considered to be any one of the following characters:  ( ,  ) ,  { ,  } ,  [ , or  ] . Two brackets are considered to be a  matched pair  if the an opening bracket (i.e.,  ( ,  [ , or  { ) occurs to the left of a closing bracket (i.e.,  ) ,  ] , or  } )  of the exact same type . There are three types of matched pairs of brackets:  [] ,  {} , and  () . A matching pair of brackets is  not balanced  if the set of brackets it encloses are not matched. For example,  {[(])} is not balanced because the contents in between  {  and  }  are not balanced. The pair of square brackets encloses a single, unbalanced opening bracket,  ( , and the pair of parentheses encloses a single, unbalanced closing square bracket,  ] . By this logic, we say a sequence of brackets is considered to be  balanced  if the follow...
Dani is writing some arrays in her favorite text editor NOTES. Each line of the document describes an array in the following format: Here   is the array's number of elements and   are its contents. Dani wrote   arrays in the file and left for lunch. To her dismay, her little brother Nik deleted all the newline characters from the file while she was gone! For example, consider the file in the table below: Given the contents of Dani's NOTES file with all the newlines removed, find the value of   (i.e., the number of arrays in the initial file). Input Format The first line contains an integer denoting   (the number of integers in the file). The second line contains   space-separated integers describing each respective value in the file. Constraints Output Format Print a single integer denoting  . Sample Input 0 11 5 4 5 4 3 3 2 1 4 1 4 Sample Outpu...