News for hackers. Stuff that matters.
Re:What's Wrong with Tech Hiring by indigochill on Thursday September 16, 2021 @05:13AM (#28549584)
> they are to filter out people who simply can't program.

The problem is they also filter out people who get nervous during tests. I'm someone who marginally failed a programming test and am now one of the most in-demand developers at my company (where I failed the test). The tech director who rejected my failed test has since told me not hiring me to his team at that time was one of the biggest mistakes of his career and I've also heard he's stopped being a believer in programming tests because of my application.

I've also been involved in hiring decisions and I've hired people who have bombed programming tests (and in ways where it was clear they just didn't grok the logic they should have). They've also been perfectly fine contributors, because our test questions required knowledge that wasn't going to be relevant (a CRUD-gluer doesn't really need to be proficient with geometry).

I still believe programming tests are useful, though. In the hiring I've done, it has been one factor to discuss during the interview. We always give developers a take-home test and then discuss the results in the interview. If they messed up, we illustrate where their solution is wrong and see if they're able to reason through the problem. If they didn't mess up, hey, that's a great sign.

If we can see them really start re-reasoning through the problem, that's a good sign that they (a) don't take programming failure personally and (b) are the sort of person who will re-evaluate what they think they know. On the other hand, if they just throw up their hands and give up without really giving the problem any extra effort, that's a bad sign. Our reasoning for this approach is that everyone writes bugs, but nobody gets to give up when fixing bugs.

As an aside, we've never tested someone who just couldn't write a for loop at all, so it's possible our hiring pool is different and so our needs/solutions are different.

And for context, the take-home test questions we use (they're always the same and they're not a secret) are:

1. Given a rectangle and a point, write a function to determine if the point is within a certain distance of the rectangle.

2. Given a string, write a function that determines if any permutation is a palindrome (this one's for the over-engineers who don't first think through the problem)

3. Write a CLI dice game where the computer cheats to maintain around a 70% win rate (there are some basic rules for scoring I'm leaving out for space - this one people rarely get totally wrong, but talking about why they picked a particular cheating mechanism can be enlightening).

Re:What's Wrong with Tech Hiring by GlennS on Thursday September 16, 2021 @07:51AM (#28550511)
Is the answer to (2) just something like this?

If len(word) is even, check that all the characters in it appear an even number of times.

If len(word) is odd, check that all the characters in it appear an even number of times except 1.

Re:What's Wrong with Tech Hiring by loup-vaillant on Thursday September 16, 2021 @08:27AM (#28550844)
I don't think you need to test for the length of the word. You just need to have at most 1 character that appears an odd number of times. My first instinct would be to scan the word character by character and use a set to check the number of occurrences:

  has_palindrome(word)
      s = empty_set
      for c in word
          if s.contains(c)
          then s.remove(c)
          else s.insert(c)
      return s.size() <= 1
If I'm not allowed to depend on an existing set implementation, I would likely fall back to a quadratic solution that counts each character. If there are special performance concerns I may sort the word before hand, or implement a special kind of set.
Re:What's Wrong with Tech Hiring by WJW on Thursday September 16, 2021 @09:02AM (#28551174)
If the string is known to be in some specific alphabet (ie only lowercase a-z), you could use a 32-bit integer as an array of bools and toggle the individual bits between false and true. The final s.size() could be done with popcount(). Not even any sets needed.

(This type of stuff might fail the "overengineering" test that the grandparent comment talked about though.)

Re:What's Wrong with Tech Hiring by loup-vaillant on Thursday September 16, 2021 @09:34AM (#28551574)
Whether that's over-engineering or not really depends on the data. For this particular interview question we might assume we have very little data to process, but real applications might want to scale that to a point where you actually care about performance (MMO permutation palindrome checker or whatnot).

Personally, I'd use the simplest implementation as a reference, and use it to test more optimised solutions if I ever need them.

Re:What's Wrong with Tech Hiring by hn_go_brrrrr on Friday September 17, 2021 @02:40AM (#28562015)
You have non-quadratic alternatives. Sort the string and then start iterating through the characters. Keep a boolean for if you've ever seen a character an odd number of times. The first time you get an odd count for a given character, set the bool to true. The second time, you see the bool is already true so you know the word isn't a palindrome and can immediately return false. If you get to the end of the string without hitting that condition, return true.
Re:What's Wrong with Tech Hiring by loup-vaillant on Friday September 17, 2021 @04:09AM (#28562601)
Yes, that's what I had in mind when I wrote "I may sort the word before hand".

Emphasis on "may", though: for small enough words, sorting may very well slow us down, so it really depends on the data: are we processing long words, or lots of small words?

Re:What's Wrong with Tech Hiring by GlennS on Friday September 17, 2021 @05:23AM (#28563047)
Oh yes, that's definitely better.
Re:What's Wrong with Tech Hiring by HeyImAlex on Thursday September 16, 2021 @09:01AM (#28551152)
abcba is a palindrome
Re:What's Wrong with Tech Hiring by loup-vaillant on Thursday September 16, 2021 @09:25AM (#28551457)
Yes it is, and it wouldn't fail my algorithm:

  a -> not in set -> add a    (a)
  b -> not in set -> add b    (ab)
  c -> not in set -> add c    (abc)
  b -> in set     -> remove b (ac)
  a -> in set     -> remove a (c)
  Set has 1 <= 1 element  ->  return OK
(Of course, "aabcb" would return yes as well, but that's the whole point: we're not asking whether a string is a palindrome, but whether any one of its permutations is.)
Re:What's Wrong with Tech Hiring by Aeolun on Thursday September 16, 2021 @10:51AM (#28552569)
I dunno, as a CRUD gluer, Nr 2 is immediately understandable now that I’ve seen someone write a super simple alghorithm for it, but I would never figure that out for myself unless I spent a major amount of time (as the originator of that simple method undoubtedly did themselves, and more than I’ willing to spend on your interview).
Re:What's Wrong with Tech Hiring by loup-vaillant on Thursday September 16, 2021 @12:13PM (#28553631)
Actually, the general answer came to me in about 5 seconds. I may have been lucky, though.

The crux here is to notice that the order of the letters in the word we're given does not matter (because of the "any permutation" part). So it must be a matter of counting the letters. GlennS got it right: https://news.ycombinator.com/item?id=28550511

The second insight was that only the parity of occurrence mattered. Having 2 or 4 or 6 times the same letter is the same as not having the letter at all, so I only have to retain "zero" or "one" for each letter. Sets are perfect for this: "zero" means "not there", "one" means it's there, and at the end I can tolerate at most one odd letter.

Re:What's Wrong with Tech Hiring by Aeolun on Thursday September 16, 2021 @08:24PM (#28559591)
That’s quite possible. And probably because you’d worked on something where this applied before.

Also exactly the reason I posted my message since that doesn’t apply for everyone. People that already know may be blind to that though.

Re:What's Wrong with Tech Hiring by estomagordo on Thursday September 16, 2021 @05:42AM (#28549723)
Sounds like fun!