I don’t think this is how you are meant to solve this challenge. Using the built-in API is really not much different from copying code. On the other hand, I’m sure plenty of people have solved this challenge by copying code. The algorithm isn’t exactly that easy to come up with.
I know, like I saw the hint of the question. The code is too long. I tried to understand how it works ( didn’t understand it fully but, I tried ) eventually I will ask someone or AI to help me understand it by breaking it into smaller chunks.
Did you succeed in understanding the exercise and the code? Let us know if you still have questions. Is there a specific aspect about how the code works that you would like to discuss? Probably something that you learned after consulting other sources like AI? Could you maybe share valuable prompts for other people to use?
And also if you can mention what prompted you to go directly to the solution? What do you think that made it difficult for you to start the exercise by yourself in the first place?