Re:A Brutal Look at Balanced Parentheses, Computing Machines...
by braythwayt on Saturday February 23, 2019 @08:09AM
(#19233184)
It’s my favourite (“favourite” is not synonymous with “best” by any metric other than amusement) solution as well:
If we're allowed to use more memory than a simple stack, this is my favorite super-cheaty solution. It abuses ruby's builtin string manipulation to recursively delete inner matched pairs (all that is really needed is a "slide remaining string left 2 chars" function). Since this only needs to match two-char long inner pairs, it trivially extends to multiple matched bracket types.