Given a string containing only bracket characters '(', ')', '{', '}', '[', ']', determine if the input string has balanced brackets. An input string is valid if open brackets are closed by the same type in the correct order. Each closing bracket must match the most recent unmatched opening bracket.
Examples:
Input: brackets = '()[]{}'
Output: true
Explanation: All brackets are properly matched and in correct order
Input: brackets = '([{}])'
Output: true
Explanation: Brackets are nested correctly with proper matching pairs
Input: brackets = '(]'
Output: false
Explanation: Opening '(' does not match closing ']'
Input: brackets = '([)]'
Output: false
Explanation: Brackets are not in correct order - ']' closes before ')'
Input: brackets = null
Output: false
Explanation: Null input is considered invalid
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay October 2026 (Oct 16–31)Sponsored by FLXBL
Contest runs October 16 - 31. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 16 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.