We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
From the problem description, rota can be as high as 1,000,000,000. On the innermost ring, l can be as small as 4. This could lead to that one innocuous-looking loop running up to 250,000,000 times on a given ring. Try replacing that loop with something like this:
rota = rota % l;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Layer Rotation
You are viewing a single comment's thread. Return to all comments →
This is your culprit:
From the problem description, rota can be as high as 1,000,000,000. On the innermost ring, l can be as small as 4. This could lead to that one innocuous-looking loop running up to 250,000,000 times on a given ring. Try replacing that loop with something like this: