Some questions can be answered easily by using specific language library. For example Java has Set, Maps, and List. Is it possible to answer those coding questions during interview by using these library or should we go more with a traditional down to earth approach, making it a C- kind of answer?
closed as primarily opinion-based by durron597, user40980, gnat, Bart van Ingen Schenau, GlenH7♦ Jun 17 '15 at 18:11
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
I think that the best solution is to offer to answer with both!
Start off with "Unless there is a compelling reason not to, I would use the blah function of the blat library, but if that were not appropriate for some reason, I would consider implementing from scratch. Would you like me to walk through the algorithm? "
Typically, at least in my experience, the interviewer will specify whether you should use standard library features or not. And even if data structures like those you listed don't exist in the language's standard library, sometimes they're okay with you using them anyway and assuming they are implemented or you know how to implement them.
Usually they're either looking for a high-level concept (in which case they'll tell you to feel free to assume Set, List, etc. exist and can be used), or they'll specifically ask you to implement a Set, List, etc. from scratch, in which case it's clear that you would not use the built-in one.
And if it's not clear, ask!
Perhaps you should be able to, sadly you can't. I once interviewed at a large (think 10^100) company, where an interviewer wrote a list up on the whiteboard like:
1, 4, 2, 2, 12, -3
and asked me to describe how I'd sort it. I responded thus:
because that is how I would sort that list. I know Big-O and the costs of a few sorting algorithms, but I bet someone whose job is to write a library method for sorting a list can do a much better job than I can. I argue that being able to rely on, understand and use the work of other people is much more important for 21st-century software engineering than being able to reimplement the solution to a problem that was already solved by IBM card machines before WW2.
[Of course, I wasn't offered the job...]
It really depends on the question. If they ask you to implement a linked-list, then most likely they are testing you on your data structure skills and not in the memorization of the name of the LinkedList class from the collection framework. Also, if they are asking to solve a puzzle using a data structure, then using a class from the collection framework might be the appropriate choice. Just recognize the intention of the question and if you are not sure, then just ask.
If someone asks you how to do something in Java, the correct answer should always be to use the facilities built into the standard library. A former co-worked of mine who was a C developer would interview Java developers and ask them to write how to reverse a linked list on a white board, he was looking for his C specific solution, which for a developer that will only be doing Java is the incorrect solution. The correct solution in Java can only be Collections.reverse(), anything else shows a lack of familiarity with idiomatic Java.
If they are asking and expecting something other than idiomatic Java, then you need to clarify that.
I honestly don't see what use questions like this can possibly give an interviewer. I suppose if you where interviewing an intern and wanted to be sure they'd had, and hadn't flunked their data structures class, sure...but I just don't see how these questions actually answer anything useful. Being able to regurgitate a linked list implementation on request does not a programmer make, and a person who cannot is not necessarily clueless either.
On the other hand, asking about how to USE these structures can be beneficial. That's what a programmer is actually going to do anyway. If you know the basic components of your data structures then you can better gage which is useful and where. Then you can take your time making your own implementation if it's actually necessary, with the aid of unit tests and a compiler (rather than a whiteboard).
Some interviewers claim that it helps them gauge how a person thinks. They expect you to talk about your process of solving the problem out loud. I see two problems with this:
1) It's not an interesting problem. There's nothing to think about.
2) Many people are derailed when trying to "think" out loud. The amount of brain centers that have to be involved in that process are much greater than just solving the problem. Some people are helped by this, other (and they may be very good too) people end up getting too distracted. This doesn't mean they're bad communicators either, just that they're the type that sit there in silence solving the problem and THEN proposing the solution they come up with.
Anyway, rant over.. I would say that if the interviewer asked you to solve a problem that involves a data structure that you should feel free to use one. I'd go so far as to propose that you can simply make up your own data structure API and just say (this does the basic XXXX operation). If they specifically ask you to write some part of a data structure though then of course you've run into one of THOSE people and will simply have to do it.
I'd suggest using the library. If the interviewer really wants me to explain the nitty-gritty, he can say "how would you do it without using a library?" or "how does that library class work?".
If he takes my initial answer as an indication that i don't know my stuff, then he's clearly a numbskull, and i wouldn't want to work for him anyway!