Ad
  • Custom User Avatar

    Ok, with Java is then out of my hands: post under the Java translator comment, so that he can be notified.

    Cheers!

  • Default User Avatar

    This solution is really Java. Java streams are part of Java 8 and you can program in a functional way (albeit in an extremely verbose way) in Java 7. Java is a multi-paradigm language. Actually this solution could be better if it did away with array indexing altogether (e.g. strArr[i + j]), and use streams entirely.

    You are right that the solution is inefficient at O(n^2).

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Which language? And feel free to share your code with a spoiler tag here :)

  • Custom User Avatar

    This is a very neat recursive solution. However, it's unneccessary complexity to use recursion.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    If I read the solution code in the test cases correctly, it's O(m x n), where m is the seed length and n is the number of values to be generated. IMHO, this is a sub-optimal solution. It can be implemented in O(n).

  • Custom User Avatar

    This solution is O(n x m), where n is the number of values to be calculated and m is the seed size. There is no need for the m term; the solution can be completely O(n). The initial Arrays.copyOf() is more clever than what I did.

  • Custom User Avatar

    Admirably terse, with no text for whether or not n is less than or equal to the seed size.

  • Custom User Avatar

    I tagged this as "best practices" because of the simplicity compared to other solutions. It is, however, order of m*n, where n is the sequence length and m is the seed length. order of n is possible, although not important where m is a constant.

  • Custom User Avatar

    Lovely. I couldn't figure out how to use streams since I was thinking of doing the map on the value of the character. Doing the map on the index instead solves that issue. Very clever.

  • Custom User Avatar

    Thanks. One thing that may color my outlook is that I learned programming back in the 1960s. Computer time was massively expensive. Programmer time was relatively cheap. Efficiency was paramount.

  • Custom User Avatar

    The definitions of these are:

    Best practise solutions tend to be a good balance of performance, readability and maintainability.

    Clever solutions tend to be very creative or make use of obscure language features. They usually are not code that you would want to put into production.

    Efficiency is valued in Codewars and this question has been asked many times as well as the topic has been debated many times (see here). Many of the coders on Codewars (like myself) have no experience coding at industrial standard or have no/little knowledge on efficient coding (such as space/time complexity). These skills are learnt at a more specialist level and therefore not everybody considers efficiency when they look at a good solution, they look at code length instead.

    However, in my opinion, efficiency is not the most important thing when it comes to coding smaller scale projects. Efficieny is a thing to look out for and try to manage. I try to structure my solutions with a "good balance of performance, readability and maintainability". I have learnt a lot during my time at Codewars and now try to keep thing compact yet efficient, but others may not have this knowledge and continue to mark these as "best practice" if the code is short. I do like one-line solutions (as long as they aren't too long) since they are snappy, to the point, simple and usually understandable.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This looks like a Python or Javascript solution written in Java.
    Truly neat functional programming, but it's inefficient and it's not really Java.

  • Loading more items...