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

)))((()(()


When I check brackets by hand or manually I do actually get my hands out and when I say open I uncurl a finger, and when I say close, I furl a finger. "Open, open, open, close, open, close, close, close". Provided I have no fingers on display at the end, then the brackets are balanced. They might not be in the right place but at least they are balanced. If I find myself starting with close then I close the lid and go and do something else.

I'm sure some sort of rather cheap algorithm falls out of the above. It wont guarantee correctness in what the balanced brackets actually contain but they will at least be balanced.


Good edge case. I’d say to immediately return an ‘unbalanced’ result once the count goes negative.


((((()


doesn't end up with zero at the end, rejected?


I was just trying to suggest a possible edge case, a failing test.


"never go negative"




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: