Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes. Actually, a more interesting example which does not complicate the statement (not the problem) too much is to check for nested parenthesis and brackets:

(([[()])) -> ok ((([](])) -> not ok

Hope OP gets this message.



In case anybody is interested, when we generalize the concept we're talking about Dyck languages.

https://en.wikipedia.org/wiki/Dyck_language


I was surprised to not see a connection made to free groups in the article.

EDIT: The wikipedia article that is.


.


Your solution incorrectly fails ({}). You need the stack.


You're right ... no counter can tell the difference between ({ and {(. Oops.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: