Sobes.tech
Intern — Middle

Verification of correct placement of brackets in a string

livecode

Task condition

It is necessary to check whether the string containing only brackets "()", "[]", "{}" is constructed correctly. A string is considered correct if:

  • Each opening bracket has a corresponding closing bracket of the same type.
  • Closing brackets appear in the correct order, meaning the last opened bracket should be closed first.
  • All opening brackets are inside pairs of brackets of the same type. Examples: Input: s = "()" Output: true

Example 2: Input: s = "(]" Output: false

Example 3: Input: s = "{[()]}" Output: true

Example 4: Input: s = "[(])" Output: false