r/ProgrammerHumor • • Jan 01 '20

A real (slightly paraphrased) prescreening experience when I was interviewing for a data science position years ago [OC]

Post image
153 Upvotes

12 comments sorted by

31

u/minimaxir Jan 01 '20 edited Jan 01 '20

If you didn't catch the trick, the trick is that you can't assume that semicolon is the only semicolon, as WHERE clauses in SQL statements could have semicolons.

Since this was a timed prescreen, I did the safe route and did a linear scan of the string to find the indices where the semicolon was outside of quoted strings in a WHERE clause. Although that passed the test cases, I did not progress to the next round (not that I was upset about it, given the Grinchy response to my first approach).

The most-correct answer would be to use a regex (which I didn't come up with at the time because I was a newbie at regex years ago), but it's not a trivial regex, and not one I'd want to write under time pressure.

34

u/[deleted] Jan 01 '20

the actual correct answer would be to use a sql parser that matches the dialect the sql statements were written in, there are many non-trivial contexts a semicolon can appear in.

6

u/minimaxir Jan 01 '20

Also true; I atleast was able to negotiate with the interviewer that I could assume quotewrapped semicolons was the only case I need to catch.

5

u/AttackOfTheThumbs Jan 02 '20

If you can write regex off the top of your head, you a freak in the sheets for sure

42

u/scp-NUMBERNOTFOUND Jan 01 '20

A bad selection process is just one like this, one that focus on tricky and unrealistic questions instead of evaluating the ability to solve a big problem by spliting it into smaller simple ones.

15

u/RoyalJackalSib Jan 01 '20

Yep, these are questions that are designed to trick people; even in a realistic scenario, a simple test will reveal that this isn’t sufficient, and a colleague is likely to notice it in a code review if you didn’t realise it yourself.

(And even then, let’s be realistic, anyone would call this out for being a strange way of dealing with SQL statements.)

Selection processes should really focus on whether people have the skills and knowledge to be an asset to a project or company, and not on whether they can or cannot solve tricky scenarios designed to be tricky.

4

u/AttackOfTheThumbs Jan 02 '20

Yeah, it's one of the things I told my boss. I took the position because there were no trick questions and they seemed like good people.

8

u/RawDawg24 Jan 01 '20

In what world would you ever need a function like this. You are somehow routinely getting many sql queries as strings separated with semi colons. Feels like a trick question whose only purpose is to make the interviewer feel smart.

6

u/EarlyJuggernaut Jan 01 '20

Tfw you write SQL on a regular basis and this shit would still get you

4

u/VestigialHead Jan 02 '20

The best answer is to tell the coder that wrote the function that returns a ridiculous string in that format to fix his shit. :)

3

u/Sekret_One Jan 02 '20

Why would I even do this?

2

u/r_acrimonger Jan 01 '20

At a place I worked that did things mostly-right, the only trick question we had was, "how do you balance a red/black tree?"

If you aaked question it was a signal to the rest of the the team that you were a "no" vote on the candidate, and that we should try to end it quickly and love on.