Ad
  • Custom User Avatar

    Easier, yes.
    Simpler, no: recursion is harder to read, understand and debug.
    Faster, barely: log10(n) is only slightly faster than converting to String.
    Space efficient, hard no: recursion will alocate more stack space than a string.

    Personaly I prefer the solution above more, as it is easier work with(all be at slower).

  • Custom User Avatar

    I cannot see the solution since I have not solved this kata in Java, but the integer part of log10 of a positive integer + 1 is equal to the length of the decimal representation of this number:

    Math.floor(Math.log10(n)+1)==n.toString().length

    (more or less, sorry if this is not correct, but my Java is not fluent :) ).

  • Default User Avatar

    can somebody explain why he used that "log10(n)" over there ?
    I haven't done any math in like 2 years so I kinda forgot about logs and how they work.
    Thanks a lot !

  • Custom User Avatar

    Not optimal time complexity. You iterate thru the entire listOfArt array for each value in the listOfCat array. It can be solved by iterating thru each array only once.

  • Custom User Avatar
  • Custom User Avatar

    This can be done much easier without having to convert your int to a string.