Skip to content

Instantly share code, notes, and snippets.

@cjsim89
Created December 6, 2023 18:05
Show Gist options
  • Save cjsim89/6e290eed84318e987fe952d9424735af to your computer and use it in GitHub Desktop.
Save cjsim89/6e290eed84318e987fe952d9424735af to your computer and use it in GitHub Desktop.
Openers/closers technical interview question

Validating Openers/Closers

You're working with an intern that keeps coming to you with some code that won't run because the braces, brackets, and parentheses are off. To save you both some time, you decide to write a braces/brackets/parentheses validator.

Let's say that:

  • (, {, and [ are called "openers", and
  • ), }, and ] are called "closers".

Write an efficient method that tells us whether or not an input string's openers and closers are properly nested.

Examples:

"{ [ ] ( ) }"   // => true
"{ [ ( ] ) }"   // => false
"{ [ }"         // => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment