InternDoor

Do the brackets close properly?

Easystack · strings

Reported in interviews at (where)

s is made only of the six characters (, ), [, ], { and }.

Return true when every opening bracket is closed by a bracket of the same kind, and brackets close in the reverse order to the one they opened in, so that they nest properly. Return false otherwise.

Example 1
Input
s = "{[]()}"
Output
true

[] and () both close inside the braces.

Example 2
Input
s = "[(])"
Output
false

The ( opened inside [ must close before the [ does.

Example 3
Input
s = "(("
Output
false

Two brackets are opened and never closed.

Limits

  • 1 <= s.length <= 100000
  • s holds only ()[]{}

Hints

Hint 1

Push each opening bracket onto a stack. A closing bracket must match the one on top, which it then removes. At the end the stack must be empty.

Where this was reported

Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.

Run your code to check it on the examples. Submit runs every hidden test.

Ready for the real one?

Engineering internships and entry-level jobs in India, newest first.