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.)

Tagged with: , , ,
Posted in Fascinations, Software Development
One comment on “Computer Science Question of the Day
  1. […] has a cool article on his blog about determining the best way to find out if a string has balanced brackets or not.  […]

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

Follow

Get every new post delivered to your Inbox.

Join 351 other followers

%d bloggers like this: