6 ms·
Why would any company want me to write an array sort instead of calling the .sort() method on the standard array class? Is that really the sort of thing they wa
by throwaway201103 6y ago
Why would any company want me to write an array sort instead of calling the .sort() method on the standard array class? Is that really the sort of thing they want their devs to code and debug and maintain by hand?
- koonsolo 6y agoIf you can't do a sort, how will be be able to do more high level complex things?
- dkdbejwi383 6y agoIf you reimplement the standard library for basic tasks, when will you ever get the time to build useful things?
- distances 6y agoI have never implemented sort after the second university compsci course. I might still be able to write one if I think about it a bit, but just not relevant at all.
- fossuser 6y agoI think testing whether someone can recall the implementation of quick sort and has practiced writing it quickly is not really testing for building complexity or solving problems. It’s testing for practiced solutions of memorized algorithms and a bit of role play. I get there’s some IQ challenge to preparing this and it’s hard to evaluate skill, but I don’t think this tests much beyond that. Want to test true basic programming capacity? Do fizz buzz, ask someone to reverse names in a string with loops - everyone should be able to do that without thinking. That’s actual basic stuff. High level or more complexity? Discuss a relevant problem the company needs to solve and how they’d approach it. Better yet discuss a problem and debug it together. Most programming is debugging anyway.
- hiq 6y agoNote that koonsolo never mentioned quicksort, only sort. You can easily make it a newbie question by just accepting any sort that returns a correct output, even with a quadratic complexity in the best case. Any programmer should be able to write that in less than 10min. And as the post you answered to alluded to, the point of the question is really just to filter out candidates who can't even write simple code, just like fizzbuzz. That's the kind of question you could ask in a first round, and then proceed to more relevant questions.
- BlargMcLarg 6y agoI haven't written a sorting method in years and couldn't remember it on the spot in 10 minutes, despite having analyzed the big ones 6 years ago. Yet, I have no problem creating a giant, modular, cookie-cutter enterprise structure, which is generally more sought after and something many hardcore leets seem to struggle with, especially once it comes down to doing more than just a fancy UML graph. We really don't need True Scotsmans on this site.
- hiq 6y agoAgain, you can make it a newbie question by just accepting any sort, including one you come up with on your own (so no need to remember). I'm sure you can design your own sort given enough time, granted 10 minutes might be too short to get it nice and clean, but with a bit more you're on the level of difficulty of fizzbuzz. To make my point clear, you can implement a dumb and inefficient sort by implementing a min function, taking this min, then iteratively call it on what's left of the array and append the values to a new array which you then return. That won't get you into FAANGM, but maybe that's enough to get some discussion started in an interview at a company that's not too much into leetcode and is trying to evaluate other skills like communication. And I do think that 99% of people who write code every week could come up with something like this or better fairly quickly.
- fossuser 6y agoThat's reasonable to me if that's the standard. The reason I jumped to quicksort in my initial reply is any sort short of quick or merge sort (or some other nlogn variant) would fail you at FAANG. You could do the naive n^2, but it better only be in the first two min and hand waved off as obviously inefficient, almost a joke that you implemented it at all on the way to writing the nlogn version, bonus points if you talk about how merge sort is nlogn in worst case and quicksort is n squared in the worst case, but in practice often faster.
- Bitkus 6y agoKnowing how to implement sort does not mean you can't do higher complexity things. These are not the basics of programming, I think. Someone the other day refused my candidacy just because I was unable to comment more broadly on the abstractions used in C# async library, which is completely off the point. If you need to do some tweaking on async, you go to microsoft or google and find it out. Most of the time you just need working knowledge of how to use async await and a few other things.
- grishka 6y agoSome people consider me a senior, yet the only sorting algorithm I actually remember and can write from scratch without consulting anything is bubble sort. And maybe insertion sort. And that's it. Both horribly inefficient. In real life I use whatever the language provides, for example Collections.sort in Java. The more general problem is just how far removed from reality are all these questions. I once tried interviewing for Google, just for fun because they sent me an email about it. They asked me about quicksort, I said that I'm able to implement it in any language I know given an hour and the ability to google things. They were apparently not very satisfied with this response. Why do you need to recite things from memory on the interviews while you'll be able to consult whatever the hell you want on your actual job? No one knows.
- tomohawk 6y agoThis is a common falacy that comes from academia. If you can't divide numbers, how will you ever do algebra? Guess what? They're different skills. A person who is good at algebra, may not be good at all at division. I know a few who fall into that category. The use a calculator.
- deleted 6y ago[deleted]
- srj 6y agoHaving a deeper understanding of how things work is important in knowing how to use even the high level constructs well. How do you choose between an ordered and unordered map? If you've implemented them even one time I bet you'll have a clearer understanding of where each one excels. If you couldn't remember how to implement quick sort or merge sort that would be one thing, but if you had no idea or never considered how a fast sort could operate that's another problem. I would never ask this in an interview but to use it as an example, it wouldn't be recall of an implementation that I'd be looking for but seeing if the candidate can identify a divide and conquer approach to the problem.
- SamuelAdams 6y agoIt demonstrates a basic understanding of underlying principles.
- user5994461 6y agoYou should use sort() and ask whether it's okay to use the built-in? They will always say it's fine and move. It would be extremely uncommon in the current decade to come across an interviewer who minds using the standard library.
- mooreds 6y agoAnd if they do mind, well, one of two things: * they are a pedantic, roll your own type of place that is full of custom frameworks and libraries that you're better off avoiding * they are big enough or specialized enough that they really need that level of knowledge I imagine the former is more common. And if you are applying to the latter, you should know that from your research. You do research companies before you interview there, right?
- chillacy 6y agoGood architects know a thing or two about material science, good electricians know a thing or two about physics, why programmers programmers be averse to understanding algorithms (i.e. the nature of computation)?