Function for checking bracket balance
PHP
Medium
functions
Task «Function for checking bracket balance»
Write a function isBalanced that takes a string containing only the characters '(', ')', '{', '}', '[', ']', and determines whether the sequence of brackets is balanced. A string is considered balanced if each opening bracket has a corresponding closing bracket of the same type and the order of brackets is correct. The function should return true if the string is balanced, and false otherwise. Constraints: the length of the string is from 1 to 1000 characters.
Input Format
A single line containing only the bracket characters '(' ')' '{' '}' '[' ']'.
Output Format
String 'true' (without quotes) if the string is balanced, and 'false' otherwise.
Examples
Example 1
INPUT
3
OUTPUT
false
Example 2
INPUT
()[]{}
OUTPUT
true
Example 3
INPUT
5
OUTPUT
false
Example 4
INPUT
(]
OUTPUT
false
main.php