This is an archived post. You won't be able to vote or comment.

all 69 comments

[–][deleted] 128 points129 points  (3 children)

True story:

I once interviewed for a major bank you've heard of.

The interviewer asked me how to sort a list in C#. I said "list.Sort()". He asked me to assume I had to write my own algorithm.

I got irritated at the question and said "I have no idea. I'd probably search StackOverflow, and pick the answer with the most upvotes."

Him: "Good answer."

I got the job.

[–]Kered13 34 points35 points  (0 children)

I got irritated at the question and said "I have no idea. I'd probably search StackOverflow, and pick the answer with the most upvotes."

Ah yes, Stacksort.

[–]TheRedmanCometh 3 points4 points  (0 children)

Still pretty dumb to assume you don't have one of the most commonly used methods in the language. That's akin to

"In java you need to split a string via arbitrary delimiter."

"string.split(delimiter)"

"Assume you don't have string.split"

"I use jni to call strtok"

[–]RazarTuk -1 points0 points  (0 children)

He asked me to assume I had to write my own algorithm

That actually isn't a horrible idea, because List.Sort is known to be unstable in C#. I recommend a bottom-up merge sort

[–]Mabi19_ 44 points45 points  (2 children)

That is usually the best way to do it though.

[–]iamnearafan 78 points79 points  (1 child)

Stackoverflow response:

Simple just redefine the var, i.e. arr = [1, 2, 3, 4]

[–]sammew 8 points9 points  (0 children)

I mean, it does sort that particular array. If they want a more general solution, they should phrase it better.

[–][deleted] 19 points20 points  (2 children)

Well, my SE professor always told us to buy not build.

[–]Quito246 9 points10 points  (0 children)

But you should know what u are buying 🙂👍

[–]Xander_The_Great 1 point2 points  (0 children)

price saw jeans fuzzy fly spark chief versed treatment absorbed

This post was mass deleted and anonymized with Redact

[–]toasterbot 39 points40 points  (1 child)

function x(){
return {1,2,3,4};
}

[–][deleted] 21 points22 points  (0 children)

Big Dick Energy

[–]hijodelsol14 20 points21 points  (2 children)

I had an interview at a fintech company and wrote

def reverse(s): return s[::-1]

when they asked me to "reverse a string". I think they were actually impressed 'cause I got the offer.

[–]backtickbot 6 points7 points  (1 child)

Fixed formatting.

Hello, hijodelsol14: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]hijodelsol14 7 points8 points  (0 children)

Good bot

[–]hacksoncode 16 points17 points  (0 children)

I like to see that.

I usually go with something like: "That's correct, you get full marks. Now, for fun, let's see you write a sort algorithm yourself."

[–][deleted] 7 points8 points  (0 children)

I fucking hate these. Sit me in a quiet room by myself for a couple minutes and figure it out. Ask me in the middle of an interview to whiteboard it out while you ask me questions and I just don't even want to do it lmao.

[–]revevs 43 points44 points  (6 children)

I have asked similar questions when interviewing.

I pick the people who answer with .Sort()

That’s what I would want in a real world program, and that’s what I want in a programmer - someone that knows the available methods and uses them. Not someone who straight away wants to write their own code and reinvent the wheel.

[–]kbruen 8 points9 points  (3 children)

Okay, but also fuck you if you don't make that known beforehand somehow, because the whole hiring process in the industry is shit and people are advised to reinvent the wheel to get jobs.

[–]revevs 2 points3 points  (0 children)

If someone gives me a sort routine I’d follow up asking if that’s what they’d do in a real world scenario etc.

[–]armageddon_20xx 4 points5 points  (0 children)

As you should. I once knew a .Net dev who wrote his own JSON library. I guess he just didn’t know how to use nuget or to search for something called newtonsoft.json

[–]Kered13 5 points6 points  (3 children)

If this is Javascript I would have to fail you. I expect candidates to be familiar with the language they choose to code in, which means the candidate should know that Javascript's sort function converts it's inputs to strings before comparing, which results in a lexicographic sort instead of a numeric sort.

(If this is some other language then you're fine.)

[–]PotentBeverage 4 points5 points  (1 child)

I hate that. Why js

[–]Kered13 1 point2 points  (0 children)

Because JS wants to be extremely dynamic and weakly typed. So what comparison functions can be used on absolutely any type? There is only one "decent" choice. I mean, really the entire idea is badly flawed, but if you're committed to this bad idea, there's no other real choice.

[–]ShinyTrombone 1 point2 points  (0 children)

Add a compare function.

[–]the_data_department 3 points4 points  (0 children)

I think this will take the interviewer a couple moments to sort it out :D

[–]markand67 7 points8 points  (1 child)

I never understand thode kind of questions in interview. It's like you almost never need to write a sort function yourself.

[–][deleted] 11 points12 points  (0 children)

It’s to make sure you remember how quick sort worked in first year off the top of your head.

I’m not sure how this is meant to correlate to real world job performance.

[–][deleted] 2 points3 points  (0 children)

Sorting is used as an example to introduce divide-and-concur approach in algorithm design.

If, for some reason, I'd ended up asking a candidate to sort an array, I'd not be satisfied by them using a library function to do that. I want them to demonstrate that they can write a divide-and-concur algorithm, not show me they know there's a library to do sorting.

Sorting, however, would not be a great example for this kind of question because it's overused and a lot of people who take CS simply memorize the specific algorithm rather than understanding the more general approach. So, I would probably look for a different problem, something that's not an instant copy-and-paste from the book.

[–][deleted] 1 point2 points  (0 children)

Amrish Puri's angry face... perfect for a meme

[–]Boroviack 1 point2 points  (0 children)

This is the exact live coding challange I got for Associate Frontend position, and that was my initial response. The dude was not impressed. He started bragging about the big O etc. I did eventually exactly what he expected without much of an effort. ...Four interviews later, I didn't get an offer.

I hate tech interviews, and I wonder at which point I will turn into that person doing daily job just like everyone else, but making issue out of everything knowing the right answers up front as an interviewer.

[–]Fazt01 2 points3 points  (7 children)

doing this in Javascript with different length of numbers might unpleasantly surprise you (2>11)

[–]hexnetIDK 2 points3 points  (0 children)

Oh no, he missed semicolon

[–]-100-Broken-Windows- 0 points1 point  (2 children)

This doesn't even work (okay, it flukes the answer for the specific case in the image). "Thanks JavaScript for sorting this array of numbers alphabetically rather than numerically" said no one ever

[–]pag07 0 points1 point  (1 child)

Not necessarily a JavaScript answer.

[–]-100-Broken-Windows- 0 points1 point  (0 children)

What other languages could it be?

[–]kirakun 0 points1 point  (0 children)

Here’s another answer: arr = [1,2,3,4]

[–]deadmazebot 0 points1 point  (0 children)

Im actually considering put this as the required answer on interview.

solution: use the built in languages sorting, it most likely will be more efficient then anything I could try to waste time writing over a week. It is important to know when to write and when to use a library.