Ad
  • Custom User Avatar

    The problem you are facing is your nested loops. For small numbers like 100 they will work fine but if you get a number like 100000 then it will have to loop through 100000 number 100000 times which is doable but takes a very long time.

    If it takes longer than the codewars server allows for execution time then it will timeout.

    You need to find another method of running a check that uses less or no nested loops (the optimisation lies in the algebra before the code).

  • Custom User Avatar

    Its probably because your code is not optimised enough.

    The 3 pre-set tests each use very small numbers for n however the actual tests that get run when you submit use much larger numbers for n.

    The issue then is that if your code takes too long for the cdewars server it will time out.

    Test your code in a local environment and see how long it takes, if it takes longer than codewars allows before timing out then you will have to change your approach to one that takes les time.

  • Custom User Avatar

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