Basic Algorithms, my solution doesn't look like the one provided in the hints


I’m working my way through basic algorithms and have to say that I’m enjoying them a lot. I’m a puzzler and doing these problems feels much the same to me. I almost always have to look up the ‘helpful links’ that are provided in the instructions to figure things out but I eventually am able to write my own code after doing so. After I’m done however, I always look at the hint link to see the answer solutions. My code almost never looks exactly like the code provided in even the most basic solutions (sometimes wildly different). I know that there are many ways to solve every problem but I wonder if I’m learning to think correctly if I don’t do it the way the answer solution has done it.

Feeling insecure about my answers even though they seem to get the job done…


You are getting the most out of freecodecamp exercises by avoiding the urge to copy or look up solutions

As hard as these problems seem at first keep in mind they all have solutions - you should relish the chance to work on such problems - real-world problems are often not readily solvable - at least there’s nobody to hand you a solution - if you don’t develop genuine problem-solving skills now it is going to be downright scary later


I think it’s like you said…there are different ways to come up with a solution…you happened to come up with one they didnt use in the answer solutions. That happens to me a lot…most of the time actually. The only time I really feel down about it is when it takes me like…50 lines to solve something that the solution solved in say…5. (its happened LOL) but Im also proud of myself for being able to think critically and come up with a solution, all on my own, that actually worked.

Im on the intermediate algorithms now, and Im finding myself finding ways not just to make it work, but to try and make it more concise too. And I know for sure thats just a skill Im going to learn through practice and experience…the more familiar we get with patterns in problem solving, the easier it will be to recall and use it. But just starting out? Oh jeez…just being able to think up any way to solve a problem is a major win…esp with no hints. Nothing to feel insecure about at all!!


Put 100 developers in a room and give them a problem. They’ll come up with (at least!) 100 different answers :slight_smile: If your code passes all the tests, and you understand what you did, it’s all good.


Thanks for replying! Reading this made me feel much better. I really enjoy doing these code challenges and it helps to know that coming up with an answer that looks different is normal. Thanks again, and best of luck with intermediate algorithms!


The code is there to be an example for what you do on the challenge, that being said it’s not the solution so copying and pasting won’t work. The goal is each challenge is to present to you a problem and make you work out the solution, your first attempt to solve it will often fail, by working through each challenge you learn a new concept and actually understand it. freeCodeCamp produces better developers since one of the strong focuses is problem solving, not just learning language syntax. That being said even I’m guilty of lazily coding at types and typing ourArray rather than myArray and so forth while working on freeCodeCamp, luckily when my code doesn’t work it refocuses me. Keep in mind the hints generally require you to change more than just ourArray to myArray, other changes are added in to make sure you truly understand what you are doing.

You should see some of my early code where I used IF statements for case testing, it was a disaster to manage, then I learned about Switches. They’re a miracle and provided for many new solutions :smiley:

You can’t copy and paste solutions, it’s against freeCodeCamp’s academic honesty policy.


Awe! I’m so glad I could help and put your mind at ease!! I really think that logic and problem solving are so creative because of all the different paths you can go on to get to a solution.

As you go on, you can go back over your solutions to see if you can find even more efficient solutions. Im really looking forward to the day I can look back at my old code and be so much better at it that I’m able to cringe at how awful they are :laughing:


Hey guys, I really appreciate your responses. I just want to clarify, if you re-read my first entry to this conversation, you’ll see that I’m not copying answers. To the contrary, I mention that I enjoy the challenges and coming up with my own answers. I do look up helpful articles on MDN that are provided in the instruction to learn how I can use splice() for example. After I write my own code and it passes, I do like to look at the answer solutions and hints. All I wanted to say is that my answers (my own written code), though they pass tests, they don’t always resemble the answers in the hint links…and wondering if that is a bad thing.


Not a bad thing at all. There’re multiple ways to solve a coding challenge. Some are more efficient than others, but efficiency is something you learn with experience. So long as your solution works, you’ve solved it. That’s a win and you’ve learned stuff along the way.

As for seeing other’s solutions, the best thing to do here is try to understand why they coded it that way. That’s a second chance to learn and improve.

You’re solution is good. Their solution is also good. Learn and see which you like better.


You said you like to look at answer solutions and hints, make sure you are spending at least 15 minutes of research and problem solving time before looking at hints/solutions, then make sure you understand what you’re doing, build upon that solution/hint, and continue to the next challenge.


She tried to clarify…she’s not looking at the hints / solutions until -after- she has already solved it on her own…

I do the same… after I have figured it out on my own, I then go look to see other ways it could have been solved so I can see how my solution stacks up and learn from other, most likely better ways of coding it out than what I already came up with.

If I come across something crazy difficult, I give myself at least a day before Ill even look at a hint… sometimes Ill move on to the next problem and then go back to the one Im having problems with…most times, just a bit of a break is what I needed. I have to be desperate and beyond frustrated for a few days to look up the solution before I have solve it…But thats cause I’m stubborn lol


Former paramount leader of the People’s Republic of China, Deng Xiaoping, once said: “it doesn’t matter if the cat is black or white, any cat that can catch mice is a good cat”.

Now, he was talking about communism and capitalism, but the point still stands: whether it’s your (perhaps somewhat bloated and bourgeois) “capitalist code” or the more Spartan “communist code” of the model answers, as long as it gets the job done, that’s the main thing.

With that said, you should still take a little time to observe (and hopefully learn from) the model answers after completing each algorithm challenge. Learning different perspectives, and perhaps some best practices, will do you a lot of favors in the future, especially in those cases where you find your code really isn’t up to the job in terms of performance, readability, or some other relevant characteristic. In other words, when you find your code is neither a black nor a white cat but a platypus instead. And platypuses are terrible at catching mice.


Well said! I will take this advice to heart!


It’s been said many times here already, but I’ll say it again then add my own take: Don’t worry about whether your solution is the same as those provided in the hints/solutions section of fCC. Everyone solves problems differently.

My take: When I was first learning to program I was always taught to 1) make it work, 2) make it clean, and 3) make it optimized… in that order. Each pass over your solution should result in a clean-up or optimization of that solution, learning a new and better way each time.