Is using known algorithms to solve questions undesirable?

Hi ! I’ve been trying to solve the [https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it] Question where the LCM of all the numbers in the range provided is to be found.
I tried my own methods by mainly using modulus operator but the script timed out for larger ranges.
I used Euclidean algorithm [https://stackoverflow.com/questions/3154454/what-is-the-most-efficient-way-to-calculate-the-least-common-multiple-of-two-int] referenced in this answer and implemented it to finally get the answer.

Is this cheating?

If you just copy and paste code from Stack Overflow, you are just cheating yourself. If you took a plain language or pseudo-code written algorithm and converted it to JavaScript to solve the challenge, then I would say you took information on a better approach to solve a problem and implemented a solution on your own.

In the latter, you actually learn something and are not cheating yourself.

1 Like

If you design a new algorithm that works, great. But this isn’t a theoretical math course.

If you understand the Euclid algorithm, then write code for it, you’ve learned.

Frankly, even if you copy the code from wiki, or stack, and it works, you have still learned what solution solves the problem, now you can study why. You can go back and a) immediately rewrite it without referencing b) do it again in 6 hours c) do it again tomorrow, etc until you learn it

Thank you for the replies. I followed the pseudo code from Euclid’s implementation in Wikipedia.