Home>

The other day, I had the following problem in the coding test.
I didn't understand well because the meaning of the question sentence was English.

Implement function verify (text) which verifies whether parentheses within text are
correctly nested. You need to consider three kinds: (), [],<>and only these kinds.

Examples: Examples:
 verify ("--- (++++) ----")->1
 verify ("")->1
 verify ("before (middle []) after")->1
 verify (") (")->0
 verify ("<(>)")->0
 verify ("([<>()]<>)")->1
 verify ("([)")->0

In Japanese
Implement the function verify (text) to verify that the parentheses in the text are properly nested
Only three types, (), [], and<>, need to be considered.

However, I didn't understand the meaning of the problem statement.
I'm guessing, but I think I should check if there are parentheses in the argument of the verify function.
I think, but I can't confirm it.

The meaning of someone's question,
And if there is any reference to solve it
I would appreciate it if you could tell me.

  • Answer # 1

    Isn't it simply possible to get the correspondence between parentheses (including the nested structure)?

    OK example:([]),[()],[] ()
    NG example:(] [),) [] (,)] [((,([)],([[

  • Answer # 2

    You could create a function that takes a string as an argument and checks if the parentheses correspond in the argument.

  • Answer # 3

    If it's a common programming language, it's probably true, but it's about whether the opening and closing brackets correspond properly.

    Also, since any string is included in the parentheses, if another kind of parenthesis appears there, it is necessary to check the correspondence between the opening parenthesis and the closing parenthesis.

    (Whenever appears,)Must be closed with, for example([[Appeared]Before the inner parenthesis is closed with)If the outer parenthesis is closed with, it will be NG. (This is a nested case)

    Do you understand the explanation?