Computer Science Question of the Day

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


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 thought on “Computer Science Question of the Day”

Leave a Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s