Easy: two nested loops and a counter. Outside loop loops over the string looking for an open bracket. Inside loop loops over the string from the outer loop's index looking for the matching bracket.