Computer Science Question of the Day


Fun question for all the CS nerdz out there:

What is the simplest and/or most efficient function you can write to determine whether a given string has balanced brackets or not?

Examples:

  • Balanced: “(This is balanced)”
  • Not Balanced: “(((This is *not*) balanced.”

Function prototype:

bool stringHasBalancedBrackets(string inputString)

The function should return true if the brackets are balanced, otherwise false.

(BTW, there is a great solution on Stack Overflow; I’m looking to see what everyone can come up with off the top of their heads.)

1 Comment

Leave a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s