Ad
  • Default User Avatar

    Vernon, it wasn't a criticism, just was curious as to why you chose to do it that way. My apologies if it came out as insulting. :(

  • Default User Avatar

    Why are you doing it this way? You know under the covers that ArrayList essentially has to re copy when it allocates more space when the underlying array runs out of space right? Which is O(n) + NLog(n);

    Then additionally you're going to call toArray, which is going to do another scan of the full size, so your time complexity will be O(2n) + n(log(n)) and your space complexity will be O(2n) one for the arraylist and one for the array...

  • Default User Avatar

    even with tail recursion, there's still more over head especially for a problem like this? Tail recursion can also mask infinite recursion.

  • Default User Avatar

    I still think there's value in what this exercise really gets at, most algorithms today are simply math. How you write that formula in your code is up to you, but this is a math problem, not particularly a coding exercise.

  • Default User Avatar

    Math, write out the a few cases, do you notice a pattern? Then your code should try and force the other player into the position you don't want. The code that's running this definitely is just taking two instances of your class(add some System.out.println's) very easy to detect.

  • Default User Avatar

    big O notation is important for an algorithm, most of these problems aren't language specific, and while yes one could use language proprietary libraries which have great algorithms already, what's the point if you don't understand why they are so great and under what cases?

    Why else are you doing any of these?

  • Default User Avatar

    Part of the value of not seeing all the unit tests is forcing your mind to consider other corner cases or vulnerabilities in your code.

    If you really can't figure it out and are in a time crunch, add for loops to show you the function inputs, and then use that information to update your test.

  • Default User Avatar

    could anyone beat algorithm is O(b) + O(a) time and O(b) + O(a) space?

    I think this algorithm is impossible to complete without using additional space if we aren't allowed to modify the arrays, the problem didn't stipulate that requirement, but still an interesting constraint to consider?

  • Default User Avatar

    Could anyone do better than O(2n) space and time complexity in a WCS? And O(n) space and time complexity in a BCS?

  • Default User Avatar

    Could anyone beat an O(n*m) + O(m) and O(m) space complexity?

  • Default User Avatar

    is the drawing showing up for other people? I'm on chrome so much like wikipedia my assumption would be that it always works :P.

  • Default User Avatar

    Would have liked to see the exercise ban language API's. I feel like there's value in understanding the Big O Notation analysis for substring/indexOf/etc.. type algorithms.

    Lot of these problems in text parsers.

  • Default User Avatar

    Java under the covers sometimes has optimzation regarding tail recursion and/or thresholds for different algorithms.

    Aside from the bounds given by the example(bounds check), this realistically could cause a stack overflow exception.

    Aside from the convenience and syntactic benefits of recurison, did you have another reason for using this over an iterative algorithm?

    The same algorithm can be done in a simple for loop, which would never run the risk of a stack overflow exception, also wouldn't have the overhead of recursion.

  • Default User Avatar

    This assumes the expected is the last number in the sequence, not the first, problem might have been updated, or this won't work

  • Default User Avatar

    you're using Java's arrays.sort which is mix of insertion sort and merge sort; going to be around O(nlog(n)) and use O(n) space, and then you're making another list adding another O(n) space when you could have done this with a one pass O(n) and O(1) space because?