Live data from Hacker News

Most candidates cannot solve this interview problem

twitter.com

21–28 of 28 posts

Re: Most candidates cannot solve this interview problem

#21

Notably, none of the answers given (despite being clever solutions to get the data) output the exact format requested. [("..",..),...]

possibly because it's much harder (maybe impossible?) to do in languages that don't have native tuples, which appear to be the ask.

The input string is quoted, so the output appears to be an array (not a string type).

My stab at it in Javascript resulted in:

    function collapse(a) {
      collapsedArray = [];
      for (let i=0; i
This outputs `[["a",2],["b",2],["c",1],["d",2],["e",1]]`. Without native tuples in Javascript (or JSON), I could construct a string which replaces the inner brackets with parens, but that would be pretty contrived, as the output requested isn't quoted.

Re: Most candidates cannot solve this interview problem

#22

Notably, none of the answers given (despite being clever solutions to get the data) output the exact format requested. [("..",..),...]

possibly because it's much harder (maybe impossible?) to do in languages that don't have native tuples, which appear to be the ask. The input string is quoted, so the output appears to be an array (not a string type). My stab at it in Javascript resulted in: function collapse(a) { collapsedArray = []; for (let i=0; i This outputs `[["a",2],["b",2],["c",1],["d",2],["e",1]]`. Without native tuples in Javascript (or JSO…

> the output requested isn't quoted.

Input: "aaaabbbcca"

Output: [("a", 4), ("b", 3), ("c", 2), ("a", 1)]

The input and output is explicit. The interpretation is a talking point.

Serialization into parens is not native for most? scripting languages. Creating a string would probably be most efficient for the output format, for sure. It's important to remember that interview questions are not just about the algorithm (for which this is trivial) but the requirements. Asking if the double quotes are representing strings (and what kind of strings for some languages) is part of the natural back-and-forth of an interview.

Re: Most candidates cannot solve this interview problem

#23

I think this approach might backfire: If purpose of the question is to test the candidate's knowledge of common libraries, then it probably is way to easy to be indicative, this kind of knowledge should be tested for something the candidate can't find by googling for 5 minutes. If the purpose is to test algorithm design, its also way to basic.

While most of the comments on the Twitter thread use fancy functions from common libraries, you should be able to solve this problem without the need for googling and without those fancy functions.

While I agree that this is way to basic to test AD skills, if it's really true that there is a sizable percentage of people that is unable to solve this problem, this might be a good way to weed those out, before starting with the 'real' questions.

Re: Most candidates cannot solve this interview problem

#24
post #7

Can I solve it? Yes. Is it a reflection of how well I can do my job? No. Will I be solving these kinds of problems at this job? Very unlikely. This is a massive waste of everyone's time and tells you nothing about the candidate's ability to do the job. Try again.

If most candidates cannot solve it in 25 minutes (while being a simple task), then it is a valid test

    [(c, sum(1 for _ in same)) for c, same in itertools.groupby(s)]

Re: Most candidates cannot solve this interview problem

#25
post #24
post #7

Can I solve it? Yes. Is it a reflection of how well I can do my job? No. Will I be solving these kinds of problems at this job? Very unlikely. This is a massive waste of everyone's time and tells you nothing about the candidate's ability to do the job. Try again.

If most candidates cannot solve it in 25 minutes (while being a simple task), then it is a valid test [(c, sum(1 for _ in same)) for c, same in itertools.groupby(s)]

Does this a actually solve it? It should only sum when the character next to is the same as the previous. a is counted twice: ([a, 3], ... [a, 1])

While I agree that such interview questions are bad, they also give the interviewer a view on how the interviewee attempts to solve a problem.

Edit: typo

Re: Most candidates cannot solve this interview problem

#26
post #24

Earlier quoted context omitted.

If most candidates cannot solve it in 25 minutes (while being a simple task), then it is a valid test [(c, sum(1 for _ in same)) for c, same in itertools.groupby(s)]

Does this a actually solve it? It should only sum when the character next to is the same as the previous. a is counted twice: ([a, 3], ... [a, 1]) While I agree that such interview questions are bad, they also give the interviewer a view on how the interviewee attempts to solve a problem. Edit: typo

Yes, it does solve it. It produces the expected output (`a` should occur twice)

Here's solution that doesn't use itertools.groupby() https://docs.python.org/3/library/itertools.html?highlight=i... :

    result = []
    prev, count = None, 0
    for c in s+"\0":  # note: assuming "\0" can't be in `s`
        if c != prev: # starting new sequence
           if count:  # save count for old sequence
              result.append((prev, count))
           prev, count = c, 1  # reset count
        else: # continuation of old sequence
           count += 1

Re: Most candidates cannot solve this interview problem

#27
post #24
post #7

Can I solve it? Yes. Is it a reflection of how well I can do my job? No. Will I be solving these kinds of problems at this job? Very unlikely. This is a massive waste of everyone's time and tells you nothing about the candidate's ability to do the job. Try again.

If most candidates cannot solve it in 25 minutes (while being a simple task), then it is a valid test [(c, sum(1 for _ in same)) for c, same in itertools.groupby(s)]

Please do comment if you downvote a correct solution.

Re: Most candidates cannot solve this interview problem

#28
post #26

Earlier quoted context omitted.

Does this a actually solve it? It should only sum when the character next to is the same as the previous. a is counted twice: ([a, 3], ... [a, 1]) While I agree that such interview questions are bad, they also give the interviewer a view on how the interviewee attempts to solve a problem. Edit: typo

Yes, it does solve it. It produces the expected output (`a` should occur twice) Here's solution that doesn't use itertools.groupby() https://docs.python.org/3/library/itertools.html?highlight=i... : result = [] prev, count = None, 0 for c in s+"\0": # note: assuming "\0" can't be in `s` if c != prev: # starting new sequence if count: # save count for old sequence result.append((prev, count)) prev, count = c, 1 # rese…

Ok, thanks. I don‘t speak enough python to understand that it solves the issue.
Post reply on HN