Hack Frontend Community

Check Bracket Correctness

Yandex
Write a function checkBrackets(str) that checks the correctness of bracket placement in a string.
  • The string can contain three types of brackets:
    Round ()
    Curly {}
    Square []
  • The function should return true if all brackets are closed and nested correctly, otherwise false.

Examples:

Input 1: "{Hi(good day)!}"
Output 1: true
Input 2: "{nice[day}"
Output 2: false
Run your code to see results.