Interview tip: Always have an iterative version ready !

Chase / Eng ghosted!
Oct 26, 2018 14 Comments

Furiously writing down a 5 line recursive solution in 2 mins is a near certain invitation to rewrite it iteratively(" that's great, but what's the risk of recursion? Oh so you know about stack space overflow, well can you try it without recursion?").

And it's not always trivial to convert it on the spot without prior preparation.

Simplest example: post order traversal of binary tree.

comments

Want to comment? LOG IN or SIGN UP
TOP 14 Comments
  • Google tc?..$FU
    Also don’t solv any problem in 2 mins.
    Take some acting lessons.
    Oct 26, 2018 8
    • Collective Health / Eng Lower
      Bqdp you’re right about the interviewee needing to blow away the interviewer. But it doesn’t follow that the interviewee should blow through a question in two min.
      Oct 26, 2018
    • Apple bqdp
      Unless they’ve seen it before, (in which case they should say so), they should do it as fast as they can. If you finish a question that usually takes candidates 10 or 15 in 2 minutes, that’s incredibly impressive.
      Oct 26, 2018
    • Shutterstock kudabobb
      Yeah except when you're at Google and you're interviewer is actually intimidated by you. In that case, maybe it *is* time to play dumb a bit. The "you don't wanna work there anyways" argument doesn't always fly.
      Oct 26, 2018
    • Google YnPX80
      My favorite thing when doing interviews is if the candidate completely blows me away and comes up with a solution I've never seen before. I don't know what's wrong with your idea of Google interviews, but feel free to do your absolute best.
      Oct 27, 2018
    • Amazon hsl44428q
      Yeah don't get why you targeted Google. There's insecure people doing interviews at every tech company. No reason to assume it's the majority.
      Oct 28, 2018
  • Amazon bHXi80
    From my experience if you solve the problem in 2 mins there will be follow up questions that will blow the interviewee
    Oct 26, 2018 0
  • Microsoft / Eng Tronkator
    It is actually very straightforward to convert into an iterative solution.
    And for the most part, a case that does stack overflow recursively but works fine iteratively is really hard to find IRL
    Oct 26, 2018 1
    • Amazon ♋️
      The iterative solution is valuable if all it does is make explicit how much is stored on the stack at each level, but I agree to a point, if there is a mechanism that will do your housekeeping for you why do it yourself.

      OTOH, if you notice that your recursive solution uses only tail calls, and the language that you are answering in doesn’t support tail call optimizations, then pointing this out and converting to a loop is probably a good thing
      Oct 27, 2018
  • Facebook / Eng useState
    Yes. For my Google interview I solved too fast and the follow up was a tweak to the question that required DP to solve efficiently wtf
    Oct 28, 2018 0
  • Conduent sAhI83
    If I suck at recursion should I just never use it then?
    Oct 27, 2018 0

Salary
Comparison

    Real time salary information from verified employees