Hacker News new | ask | show | jobs
by aiokos 3767 days ago
Is it 20% to generate something like this, which balances parentheses without syntax? If so that is seriously surprising.

  function getBalance (parenStr) {
      var count = 0;
      for (var i = 0; i < parenStr.length; i++) {
          if (parenStr[i] === '(') { count++; }
          else if (parenStr[i] === ')') { count--; }
      }
      return count === 0;
  }
2 comments

Most programmers that have any business getting hired should be able to do that. The problem is that when you interview people, you don't get a good sample of the population: The worse you are, the more interviews you have to do, because you get declined a whole lot.

In a previous job, a question like that would not even get a 20% pass rate, but it also have a lot to do with where we were sourcing our employees: If you are talking to generic contracting firms that employ people in giant, generic behemoths, you WILL get a lot of terrible candidates from them. From the powerpoint architect that hasn't written a line of code in weeks, to people that just had a job at big megacorp, and did the minimum possible not to get fired (and, in some of those corps, that's really little).

It got that bad that there were employer patterns that we considered resume black flags: Spent one year in MasterCard? Well, they hire pretty much anyone for a year, and they just don't get renewed, so we will understand that experience as 'you weren't good enough to work there, and most people there suck'.

wouldn't that just see if there are an equal amount of parentheses, not whether or not they're balanced?

For example, your code would return true for ")())((" even though nothing is balanced. I was thinking more of a stack; push to stack only on opens, pop on closes, if we get a close before an open is on the stack, then we return false.

But I only thought about it for a few minutes so it's rather rudimentary.