FunctionRacerProblemsRace

Fully Nested Brackets

EasyRecursionPython, JavaScript, TypeScript, Java, C++

A string is fully nested when it is empty, or when it starts with an opening bracket, ends with the closing bracket of the same kind, and the part between them is itself fully nested. The two kinds are () and []. So ([()]) and [[]] are fully nested, while ()[] (two groups side by side), ([)] (the kinds do not match) and ( are not.

Return True if s is fully nested and False otherwise.

Example 1

s "([()])"
returns true

( pairs with the final ), inside it [ pairs with ], and inside that () is nested around the empty string.

Example 2

s "()[]"
returns false

The first character ( is closed by the second one, so the string does not end with its partner.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems