In a balanced string certain pairs of characters or substrings always appear with the same amount. Often there are additional restrictions that those pairs also have to be ordered. The most common example is a correctly parenthesized string. See also the [palindrome] and [syntax] tags.

In a balanced string certain pairs of characters or substrings always appear with the same amount. Often there are additional restrictions that those pairs also have to be ordered. The most common example is a correctly parenthesized string.

Related tags and when to use them:

  • are strings that read the same forwards and backwards. Note that normally balanced strings aren't palindromes. For instance, () reads )( backwards. For problems which combine palindrome properties with balanced properties, like "Convenient palindrome" checker consider using both tags.
  • : Many programming and markup languages use balanced parentheses, braces or brackets to denote some form of subsection of the code. There are also languages like XML where opening and closing tags (i.e. arbitrary strings) need to be correctly balanced, as opposed to individual characters. Challenges involving syntax rules (like syntax checking or fixing) should use the tag. Additionally using the tag for syntax challenges involving balancing rules is fine if that is a significant part of the challenge.
history | excerpt history