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

    The C# version (and Java version) has broken tests for random lengths because the precision of double breaks down when the number of digits exceeds 15 or 16.

  • Default User Avatar

    The C# version has the same problem, the precision of double starts to break down after 15 or 16 digits and the tests sometimes pass and sometimes fail depending on how high the random length value happened to go.

  • Default User Avatar

    For all the people reading the solutions and thinking that this is a "best practice", it isn't.
    Yes it is clever, but it is very inefficient in runtime execution and if you get a question like this in an interview the interviewer will likely not be impressed with this answer because it doesn't show you know how to actually write an algorithm.

    This is a simple way to "solve" the problem but it doesn't demonstrate any understanding of how to actually write an algorithm which is the whole point of questions like these, especially if you are practicing for interviewing.
    Calling an existing function like this in a production system (when it doesn't cause a performance problem) is a good way to get your job done quickly but it executes 20X slower than writing the for loop yourself.

    P.S. Read my solution that presents two algorithm options for examples of the kinds of responses interviewers are actually looking for.

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

    The reversal of the array is unnecessary, just swap the print order in the returned string.
    I do like your use of Array.ConvertAll, I forgot about that method.