From f4037272d87ffa46536078da2990edcdf41be26a Mon Sep 17 00:00:00 2001 From: TanyaKhandelwal <65648613+TanyaKhandelwal@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:38:44 +0530 Subject: [PATCH 1/2] Add files via upload --- src/_Problems_/balanced-parentheses.test.js | 21 +++++++++++++++ src/_Problems_/index.js | 30 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/_Problems_/balanced-parentheses.test.js create mode 100644 src/_Problems_/index.js diff --git a/src/_Problems_/balanced-parentheses.test.js b/src/_Problems_/balanced-parentheses.test.js new file mode 100644 index 00000000..9f1a2bbc --- /dev/null +++ b/src/_Problems_/balanced-parentheses.test.js @@ -0,0 +1,21 @@ +const { parentheses } = require('.'); + +describe('Parentheses', () => { + it('Should return true only when matching brackets are there', () => { + expect(parentheses("{[()]})").toEqual('Balanced'); + }); + + it('Should return false when matching brackets are not there', () => { + expect(parentheses("{[()}])").toEqual('UnBalanced'); + }); + it('Should return true only when matching brackets are there', () => { + expect(parentheses("{()})").toEqual('Balanced'); + }); + + it('Should return false when matching brackets are not there', () => { + expect(parentheses("{[}])").toEqual('UnBalanced'); + }); + + + +}); diff --git a/src/_Problems_/index.js b/src/_Problems_/index.js new file mode 100644 index 00000000..21653180 --- /dev/null +++ b/src/_Problems_/index.js @@ -0,0 +1,30 @@ +function parentheses(s) { + if(typeof s !== "string" || s.length % 2 !== 0) return false; + let i = 0; + let arr = []; + while(i Date: Sat, 4 Sep 2021 12:16:12 +0530 Subject: [PATCH 2/2] Add files via upload Added problem statement and time complexity --- src/_Problems_/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/_Problems_/index.js b/src/_Problems_/index.js index 21653180..2aa5eed2 100644 --- a/src/_Problems_/index.js +++ b/src/_Problems_/index.js @@ -1,3 +1,9 @@ +// FIND BALANCED PARENTHESIS +// FOR '[{()}]' ---->>>> BALANCED +// FOR '[{()]' ---->>>> UNBALANCED +// Time complexity : O(n) n is the length of the string provided. + + function parentheses(s) { if(typeof s !== "string" || s.length % 2 !== 0) return false; let i = 0;