`{"id":"30e595f7-2adb-42c3-aadb-a7a4d367b32a","name":"Balanced Brackets","description":"1. You are given a string exp representing an expression.\r\n2. You are required to check if the expression is balanced i.e. closing brackets and opening brackets match up well.\r\n\r\ne.g.\r\n[(a + b) + {(c + d) * (e / f)}] -> true\r\n[(a + b) + {(c + d) * (e / f)]} -> false\r\n[(a + b) + {(c + d) * (e / f)} -> false\r\n([(a + b) + {(c + d) * (e / f)}] -> false","inputFormat":"A string str","outputFormat":"true or false","constraints":"0 &lt;= str.length &lt;= 100","sampleCode":{"cpp":{"code":"from sys import stdin\r\nexpression = stdin.readline()\r\n#write your code here"},"java":{"code":"#include <bits/stdc++.h>\r\nusing namespace std;\r\nint main(int argc, char **argv)\r\n{ \r\n //write your code\r\n return 0;\r\n}"},"python":{"code":"from sys import stdin\nexpression = stdin.readline()\n#write your code here"}},"points":10,"difficulty":"easy","sampleInput":"[(a + b) + {(c + d) * (e / f)}]","sampleOutput":"true","questionVideo":"https://www.youtube.com/embed/p-RbQyQevTQ","hints":[],"associated":[{"id":"6755a750-15f9-4039-b77c-61245fb4a38a","name":"Which application of stack is used to ensure that the pair of parentheses is properly nested?(Q Balanced Bracket)","slug":"which-application-of-stack-is-used-to-ensure-that-the-pair-of-parentheses-is-properly-nested-q-balanced-bracket","type":4},{"id":"8cf08363-e80f-4a1f-a3ce-05fa70ad0691","name":"Which of the following does the balancing symbols algorithm include? (Q Balanced Bracket)","slug":"which-of-the-following-does-the-balancing-symbols-algorithm-include-q-balanced-bracket","type":4},{"id":"d89e99db-bdc2-4acb-9d34-43c783d02b13","name":"In balancing parentheses algorithm, the string is read from?(Q Balanced Bracket)","slug":"in-balancing-parentheses-algorithm-the-string-is-read-from-q-balanced-bracket","type":4},{"id":"e8f6c36e-ba87-42d1-a728-94445ff3a0b4","name":"What is the time complexity of balancing parentheses algorithm?(Q- Balanced Brackets)","slug":"what-is-the-time-complexity-of-balancing-parentheses-algorithm-q-balanced-brackets","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9847c2b3-e3ad-4b1c-97d1-00206b1be68d","name":"Stacks And Queues For Beginners","slug":"stacks-and-queues-for-beginners","type":0},{"id":"a51512a8-27d5-443e-b394-2cbbdc61747b","name":"Balanced Brackets","slug":"balanced-brackets","type":1}],"next":{"id":"f460fac4-93fc-43a3-8d60-bf23bd17819b","name":"Balanced Brackets","type":3,"slug":"balanced-brackets"},"prev":{"id":"c689d153-9cc5-4a26-8137-a6001c37bb65","name":"Duplicate Brackets","type":3,"slug":"duplicate-brackets"}}}`

# Balanced Brackets

1. You are given a string exp representing an expression. 2. You are required to check if the expression is balanced i.e. closing brackets and opening brackets match up well. e.g. [(a + b) + {(c + d) * (e / f)}] -> true [(a + b) + {(c + d) * (e / f)]} -> false [(a + b) + {(c + d) * (e / f)} -> false ([(a + b) + {(c + d) * (e / f)}] -> false

`{"id":"30e595f7-2adb-42c3-aadb-a7a4d367b32a","name":"Balanced Brackets","description":"1. You are given a string exp representing an expression.\r\n2. You are required to check if the expression is balanced i.e. closing brackets and opening brackets match up well.\r\n\r\ne.g.\r\n[(a + b) + {(c + d) * (e / f)}] -> true\r\n[(a + b) + {(c + d) * (e / f)]} -> false\r\n[(a + b) + {(c + d) * (e / f)} -> false\r\n([(a + b) + {(c + d) * (e / f)}] -> false","inputFormat":"A string str","outputFormat":"true or false","constraints":"0 &lt;= str.length &lt;= 100","sampleCode":{"cpp":{"code":"from sys import stdin\r\nexpression = stdin.readline()\r\n#write your code here"},"java":{"code":"#include <bits/stdc++.h>\r\nusing namespace std;\r\nint main(int argc, char **argv)\r\n{ \r\n //write your code\r\n return 0;\r\n}"},"python":{"code":"from sys import stdin\nexpression = stdin.readline()\n#write your code here"}},"points":10,"difficulty":"easy","sampleInput":"[(a + b) + {(c + d) * (e / f)}]","sampleOutput":"true","questionVideo":"https://www.youtube.com/embed/p-RbQyQevTQ","hints":[],"associated":[{"id":"6755a750-15f9-4039-b77c-61245fb4a38a","name":"Which application of stack is used to ensure that the pair of parentheses is properly nested?(Q Balanced Bracket)","slug":"which-application-of-stack-is-used-to-ensure-that-the-pair-of-parentheses-is-properly-nested-q-balanced-bracket","type":4},{"id":"8cf08363-e80f-4a1f-a3ce-05fa70ad0691","name":"Which of the following does the balancing symbols algorithm include? (Q Balanced Bracket)","slug":"which-of-the-following-does-the-balancing-symbols-algorithm-include-q-balanced-bracket","type":4},{"id":"d89e99db-bdc2-4acb-9d34-43c783d02b13","name":"In balancing parentheses algorithm, the string is read from?(Q Balanced Bracket)","slug":"in-balancing-parentheses-algorithm-the-string-is-read-from-q-balanced-bracket","type":4},{"id":"e8f6c36e-ba87-42d1-a728-94445ff3a0b4","name":"What is the time complexity of balancing parentheses algorithm?(Q- Balanced Brackets)","slug":"what-is-the-time-complexity-of-balancing-parentheses-algorithm-q-balanced-brackets","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9847c2b3-e3ad-4b1c-97d1-00206b1be68d","name":"Stacks And Queues For Beginners","slug":"stacks-and-queues-for-beginners","type":0},{"id":"a51512a8-27d5-443e-b394-2cbbdc61747b","name":"Balanced Brackets","slug":"balanced-brackets","type":1}],"next":{"id":"f460fac4-93fc-43a3-8d60-bf23bd17819b","name":"Balanced Brackets","type":3,"slug":"balanced-brackets"},"prev":{"id":"c689d153-9cc5-4a26-8137-a6001c37bb65","name":"Duplicate Brackets","type":3,"slug":"duplicate-brackets"}}}`

Editor

# Balanced Brackets

easy

1. You are given a string exp representing an expression. 2. You are required to check if the expression is balanced i.e. closing brackets and opening brackets match up well. e.g. [(a + b) + {(c + d) * (e / f)}] -> true [(a + b) + {(c + d) * (e / f)]} -> false [(a + b) + {(c + d) * (e / f)} -> false ([(a + b) + {(c + d) * (e / f)}] -> false

## Constraints

0 <= str.length <= 100

A string str

true or false

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}[(a + b) + {(c + d) * (e / f)}]`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}true`

Question Video

Discussions

Show Discussion

Related Resources