You need to sign in or sign up before continuing.×
Ad
  • Custom User Avatar
  • Default User Avatar

    You need chars() to safely iterate UTF characters of a str. Strings are always UTF-8 encoded, so accessing the bytes directly would be problematic. The collect() at the end consumes the Iterator into a String.

    For better functional composition, a more flexible signature would be:

    fn no_space(x: impl IntoIterator<Item=char>) -> impl Iterator<Item=char>
    

    This way you could pass any iterable into the function (including str.chars()), and chain the function lazily, without allocating a String for output.

  • Custom User Avatar

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

  • Default User Avatar

    I believe in you, WarriorZero

  • Default User Avatar

    Ok. I get it. Generating green numbers is expensive - To do it in less than O(nlogn) would require a lot of effort (if it's even possible). However, given that n will always be <=3000, there might be a better way to do it.

  • Custom User Avatar

    I suggest to generate the first 10..20 elements or so with your code, and then examine it. You may notice a certain pattern... If so, try to make use of it somehow.

    Cheers

  • Custom User Avatar

    After I could see @Blind4Basics's answer I was able to find and fix the problem. IMO it worths mentionning in the description, that the source array shouldn't be mutated.

  • Custom User Avatar

    I'm hitting the same issue. All random tests seem to expect empty result set. Can you please share what solved the issue for you?

  • Custom User Avatar

    This is an algorithm kata. So an efficient algorithm is required.

    From the looks of it, it suggests nothing but that you're simply not capable enough for this kata.

    My only suggestion is that you shouldn't be attempting this kata in the first place (because of the huge skill mismatch), and you should go try something else.

  • Default User Avatar
  • Custom User Avatar

    Programmers and Genice .
    I write the code but it take alot of time as it +1 (add one) for each loop
    How can I solve like this problem
    Note I must +1 in one step to get the answer
    Any suggestion >>>

  • Custom User Avatar

    plz remove this question
    I get it

  • Custom User Avatar

    Translation approved

  • Custom User Avatar

    you need to clarify the "returns n th " in " Your task is to write a function green that returns n th green number, starting with 1 - green (1) == 1"

    what is the thing to return exactly?

  • Custom User Avatar

    Eng is not my native language ,
    And I work on improve it :)

  • Loading more items...