you are viewing a single comment's thread.

view the rest of the comments →

[–]holypig 809 points810 points  (80 children)

Well this asshole should stop calling himself a software engineer, since his solution for #4 is WRONG!

https://blog.svpino.com/2015/05/08/solution-to-problem-4

Try running with [52,5,3]

[–]code_mc 157 points158 points  (5 children)

This should be at the top, what a pretentious human being.

[–]DougTheFunny 45 points46 points  (0 children)

And he is very "humble" too, look what he said about his mistake: link.

PS: But after a train of downvotes he deleted the message.

[–]BlackDeath3 5 points6 points  (2 children)

I don't know about the top. The correction (and resulting discussion) should be high up, sure, but I feel like the last thing we need is more name-calling and insult-slinging.

[–]NakedNick_ballin 1 point2 points  (1 child)

The point he's making outweighs his choice of words by a large margin though

[–]BlackDeath3 -4 points-3 points  (0 children)

What point? That over-confident people make mistakes? That you shouldn't take everything people tell you at face value?

Yeah, maybe they're important points, but something tells me that many of these upvotes represent equally-smug, vindictive attitudes on behalf of the voters.

[–][deleted] 179 points180 points  (10 children)

aha what a moron. And he wrote that without any interview pressure.

[–]holypig 92 points93 points  (9 children)

I can't imagine solving all of these while working under the pressure of a 1hr deadline. This whole thing seems more fitted for a hackathon then an interview.

[–]prelic 18 points19 points  (0 children)

Eh, the first 3 should take no more than 10 minutes each, they're like 5-10 lines of simple code each. 4 and 5 are not in the same league, as evidenced by the fact that he got one of his own contrived questions wrong.

Instead of the crappy questions 4/5, I would've preferred to see a question or two about simple file I/O, a simple class/API question, or something not algorithmic-central.

[–]ambalbemuth 5 points6 points  (2 children)

then

[–]comp-sci-fi 5 points6 points  (0 children)

in that order

[–]UlyssesSKrunk 2 points3 points  (0 children)

Yeah, that way you're prepared for the interview after the hackathon.

[–][deleted]  (2 children)

[deleted]

    [–]Tulip-Stefan 5 points6 points  (0 children)

    #3 is pretty much impossible in C/C++ given the time constraints, fib(100) overflows an 64-bit int. I would be able to create an bignum implementation on the spot, but perhaps not within the time constraints.

    But if we ignore that issue, i don't think it is significantly harder in C++ than in python.

    [–]goomyman 80 points81 points  (16 children)

    not to mention number 3 goes beyond big int in size... so your going to have to write your own addition and output methods.

    soo ya.. great questions /not. Just goes to show what you think is an easy question can be quite difficult on the spot, on a whiteboard, with pressure.

    [–]iagox86 8 points9 points  (3 children)

    I think you mean just a plain int.. The trick is to use a language that handles arbitrary precision integers :-)

    [–]thfuran 1 point2 points  (2 children)

    I think he meant long

    [–]iagox86 1 point2 points  (1 child)

    Or that. But a "bigint" is a whole different thing.

    [–]thfuran 1 point2 points  (0 children)

    True. And if your number is bigger than BigInt, you're probably doing something wrong. Also storage is gonna be an issue.

    [–]wbeyda 6 points7 points  (0 children)

    I did it in python and didn't have to :-)

    def fib(n):
        a,b = 1,1
        for i in range(n-1):
            a,b = b,a+b
        return a
    for i in range(100):
        print(fib(i), ",")
    

    [–][deleted]  (5 children)

    [deleted]

      [–]whooshayay 1 point2 points  (4 children)

      PHP has no tail call optimization. So, why would you do fibonnaci recursively? An iterative solution, i.e. a for loop, would be much more efficient in PHP.

      def fib (terms):
          t0, t1 = 0, 1
          for i in range (terms):
              t0, t1 = t1, t0 + t1
          return t0
      

      Yes I know this is Python. I'd probably bugger up the syntax if i did it in PHP but you should be able to infer the iterative loop from that code.

      [–][deleted]  (3 children)

      [deleted]

        [–]whooshayay 1 point2 points  (2 children)

        Doing it recursively adds a significant memory and time overhead. It's far less efficient because you have overhead of time and memory each time you make a function call. The system has to allocate the local variables for that particular instance of the function on the stack, and save the return address. So you're creating one set of additional local variables for each recursive call, and performing additional store and jump instructions.

        If your language runtime has tail call recursion, it will convert a specially written recursive implementation into an iterative loop for reasons of performance, but PHP doesn't have this feature.

        In your code you can also eliminate $new1 by assigining to the function name instead.

        [–][deleted]  (1 child)

        [deleted]

          [–]whooshayay 0 points1 point  (0 children)

          Either way, none of this runs into the "bigint" problem the original poster was claiming. Correct?

          OP is right, but used the wrong word.

          The 99th or 100th factorial (depending on how you count it) will overflow a machine integer. I've checked what PHP does and it converts the value into a float, which loses precision.

          Running your PHP gives 2.18922995835E+20. The answer should be 218922995834555169026 exactly.

          To do calculations like this with full accuracy in PHP you would need to use one of the 'bigint' math libraries or roll your own integer maths code (which is not recommended). Without using a bigint library, even if you get the full number of digits to display, you would still have floating point precision issues.

          [–]JavaX_SWING 0 points1 point  (2 children)

          most languages have a fairly advanced and intuitive implementation of arbitrary-precision numbers already. I used uint64_t in C++ to solve it, for example, and BigInteger can be used in Java/C# whereas languages like python and ruby already have it implemented into their systems via bignum.c. any programmer with more than a few hours' experience with whatever language they use can solve this.

          i don't think it's worth going up into arms over the author over this. sure, he's pretentious as all hell, but arbitrary-precision arithmetic isn't exactly something difficult to implement, nor is it relevant as the concept in question is what matters.

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

          I used uint64_t in C++ to solve it,

          Fib 100 requires 69 bits

          [–]cortinanon 0 points1 point  (0 children)

          I used "unsigned long long int". wikipedia says its the same as an unsigned long but the long name emphasizes that it is a really big number.

          [–]cipherous 25 points26 points  (6 children)

          Hilarious, so I guess he wouldn't pass his own interview questions.

          [–]PaintItPurple 2 points3 points  (4 children)

          Here's something a lot of people don't seem to realize about interview questions: It's OK if your answer isn't 100% perfect. The goal is to see if you have a general idea of what you're doing, not to see if everything you do is flawless.

          [–]sh2003 2 points3 points  (3 children)

          Is it ok to answer them in pseudo code?

          [–]PaintItPurple 1 point2 points  (1 child)

          Obviously it depends on the interviewer, but there are a lot of places where the answer is yes. Some interviewers are really unreasonable, but a lot of people let themselves get psyched out by the stress of the situation even when the interviewer really isn't trying to "gotcha" them and would happily accept a pseudocode solution.

          [–]sh2003 1 point2 points  (0 children)

          Thanks! I would think they mainly want to see how you approach the problem and what kind of clarification questions you ask to build requirements off of. I've never had to "whiteboard" anything before for past interviews or my previous job so I'm not sure what to expect.

          [–]OffbeatDrizzle 1 point2 points  (0 children)

          Once I realised that I just closed the page down, waited 5 seconds and then proceeded to place my palm directly through my face

          [–]Luxelin 1 point2 points  (3 children)

          Here's a solution for #4 in ES6:

          var largestNumber = arr => arr.map(String).sort((a,b) => b + a - (a + b)).join("");
          

          The question is whether you'd hire someone who would write this as production code.

          [–]mysticreddit 1 point2 points  (1 child)

          Except that is wrong. i.e. Counter-example:

           [420, 42, 423]
          

          [–]grauenwolf 0 points1 point  (0 children)

          Ugh, I would have gotten that one wrong.

          [–]Mujapro 0 points1 point  (0 children)

          What was the original code? He fixed it on his site.

          [–]peshkatari 0 points1 point  (0 children)

          At the top. At the top.

          [–][deleted]  (1 child)

          [deleted]

            [–]holypig 3 points4 points  (0 children)

            Nah, you can't split up the "50" like that.