Balanced Brackets

Learn how to determine if brackets are balanced or not. This is an actual problem that software developers must occasionally solve and many dev tools have their own implementation of it. We'll learn how a code editor can pick up our mistakes and highlight exactly which brackets don't match.

Balanced Brackets

Instructions

Given a string, return true if it contains all balanced parentheses (), curly-brackets {}, and square-brackets [].

Input: String

Output: Boolean

Examples

isBalanced("(x + y) - (4)"); // -> true
isBalanced("(((10 ) ()) ((?)(:)))"); // -> true
isBalanced("[{()}]"); // -> true
isBalanced("(50)("); // -> false
isBalanced("[{]}"); // -> false

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.