Ad
  • Custom User Avatar

    You are right! Thank you

  • Custom User Avatar

    This is the quick and dirty way.
    I have no idea why this has so many "Best Practice" votes as this is a very very bad practice.

    One way to measure how well algorythms handle large inputs is Big-O notation.
    The Big-O notation of a given algorythm says how the size of the input relates to the duration of the execution.
    This solution has O(n)=n -> the larger n is, the longer it takes.

    The ideal solution to this Problem has O(n)=1
    This means that it always takes the same amount of time, no matter how large the input is.

  • Custom User Avatar

    Yeah its few lines but is it readable?
    I would never use inline if and for if it makes the code hard to read

  • Custom User Avatar

    Right now you are using logical OR to check if no requirement is violated
    If you were to check if the requirements were met instead ( <= turns into >, >= turns into < etc)
    and use logical AND to chain the checks, it would be a tiny bit more efficient.
    If any of the requirements are not met, the rest of the expression does not need to be evaluated
    as one false in a chain of ANDs will always equal false.

    In this example the impact is negligeble but it is best practice to fail fast.

  • Custom User Avatar

    I have the exact same problem.
    Is this happening because of strlen?