-2

In a coding/technical interview, your interviewer may ask you to write an algorithm -- for example, one that efficiently can return "longest possible increasing order" from a stream of numbers.

Will it be really bad if I choose to write my own algorithm instead of choosing any pre-defined algorithm? Both I and the interviewer know that a predefined algorithm may give a better result in terms of complexity and efficiency.

If you previously understood some predefined algorithm and use it in the interview you are doing the same thing as you understood before, you are not trying! Maybe it was possible to achieve better complexity if you could follow any predefined algorithm, but it is generalized! it can be possible anywhere, anytime.

2

If you previously understood some predefined algorithm and use it in the interview you are doing the same thing as you understood before, you are not trying!

Exactly the opposite. If you use some predefined algorithm use it. Or even better, know that that predefined algorithm is readily available in the standard library for language X, use it. If on the other hand you hem and haw to what should be a simple question, I'm going to have to assume you don't know the answer and quickly move on to my next set of questions.

I have half an hour with you in which I'm supposed to assess

  • Can you program your way out of a brown paper bag? I work for an aerospace engineering, and a lot of that work now requires at least some ability to program a computer.
    • For those from a CS background, I have to gauge whether mathematics and science scares them. CS majors who can easily do dynamic programming but who took Physics For Poets to dodge the science requirement may not be a good fit for my employer.
    • For those from an engineering or science, I have to gauge whether computer programming scares them, and if the know any programming language other than MATLAB.
  • Have you severely overrated yourself? It has apparently become the American way to overrate oneself to some extent. But don't rate yourself as a eight out of ten unless you're close to being a world-renowned expert. Beware: Companies have experts who can rip you a new one if you do so.
  • And equally importantly, I have to take part of my half an hour to gauge whether the candidate
    • Will you fit into our corporate culture.
    • Appears to be trustworthy.
    • Is excited by the prospect of working for us.
    • Can think.
  • accepted and upvoted! exactly the "answer" I wanted to get! thanks for the time and explanation! – ReturnZero Sep 3 '19 at 5:54
12

If you were interviewing with me, the correct answer would be to ask me. For example, if they wanted you to write code to reverse a string, in a language/library that has a reverse method on the string class:

Is it ok just to use the reverse method or did you want to see me code the actual character manipulations?

If they laugh and move on, you're good. If they say no, we want to see the algorithm, then go ahead.

Similarly, for something with performance issues:

Well in real like I would use whatever which has the complexity O(logn), but would you like me to just write a naïve implementation that shows the logic?

When I do whiteboard tasks in an interview, the most important part for me is the clarifying questions you ask, and the priorities you show you care about. You've assumed your interviewer cares most about execution time and that you're "trying" by writing everything from scratch instead of using a language or library capability you know about. Most interviewers actually value code readability and developer productivity, both of which are better served by using something predefined and well known. Unless you ask what this interviewer values, you are unlikely to get the question right.

  • This. It depends on what the interviewer is trying to find out about you from the task. No one wants to employ a developer who codes everything from scratch, on the other hand, they may want to see how you think and work (for which a more complex challenge maybe.. too complex for an interview) – mattumotu Sep 2 '19 at 13:48
  • Plus this answer highlights: never be scared to ask for clarification of requirements. To Assume make an ass out of you. – mattumotu Sep 2 '19 at 13:49
  • You get an upvote for putting "trying" in quotes. C++ programmer spotted. – Gregory Currie Sep 2 '19 at 13:55
3

Part of what an interviewer is looking for in a candidate is whether or not they will waste everyones time by making their own life needlessly difficult. Imagine you are in an interview for a carpentry job and you are given some nails, wood and a hammer, you are told by the interviewer to hammer 5 nails into the wood so he can see you do it.

If you decide to design and make your own hammer out of wood and take 2 hours to do it before you can get started on hammering the nails in, you will fail the interview. Just use the hammer that is already on the table.

In the same way, you should use any predefined algorithm you know that will accomplish the task, rather than trying to re-invent every time.

1

If they wanted you to invent something on the spot, then they would ask a question that demands it.

Instead, if the employer asks a question that creates the opportunity to use a well-known 'pre-defined' algorithm, then they're not testing your ability to write good algorithms.

No - they are testing your knowledge of well-known algorithms but also your ability to communicate the details clearly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.