Balance Brackets

Feb 7, 202010 mins read

Straight to the Point !

Are you landed to this page and rushing for the immediate solution in javascript. here you go !!

10, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89

On High level note, It worth to read in detail for a better understanding.

Table of Contents

$desc$

Problem Statement

A bracket is any of the following characters: (, ), {, }, [, or ].

We consider two brackets to be matching if the first bracket is an open-bracket, e.g., (, {, or [, and the second bracket is a close-bracket of the same type. That means ( and ), [ and ], and { and } are the only pairs of matching brackets.

Furthermore, a sequence of brackets is said to be balanced if the following conditions are met:

  1. The sequence is empty, or
  2. The sequence is composed of two or more non-empty sequences, all of which are balanced, or
  3. The first and last brackets of the sequence are matching, and the portion of the sequence without the first and last elements is balanced.

You are given a string of brackets. Your task is to determine whether each sequence of brackets is balanced. If a string is balanced, return true, otherwise, return false

1bool isBalanced(String s)

Constraints

  1. Goes here

Expected

  1. Goes here

Test Cases

Below one is three nested

1s = {[()]}
2output: true

Test Cases

1bool isBalanced(String s)

Foot Note

1bool isBalanced(String s)

Solution Intro

Lets see the list of approaches and their complexities.


ApproachTime ComplexitySpace Complexity
1Brute ForceO(n+mO(m+n)
2$Approach 1$O(n)O(n)
3$Approach 2$O(n)O(n)
4Time OptimizedO(n)O(n)
5Memory OptimizedO(n)O(n)

Solutions

With no further due, lets take a example of code solutions.

Brute Force

Description

1Code goes here...

$Approach-1$

Description

1Code goes here...

$Approach-2$

Description

1Code goes here...

$Time-Optimized$

Description

1Code goes here...
### $Space-Optimized$Description
1Code goes here...