Does it count as cheating? I will be glad to read your opinions

Whenever it is difficult to solve algorithm challenges, I check the output part and start playing around with my code, until it passes all the tests. And while doing this, I really feel like I am shamelessly cheating.
Guys, what do you think - should I stop doing this. After all I am new may be it is better to not to look at outputs and tests before solving the algorithm challenges logically. Also in real world programming do we get provided with outputs for the corresponding inputs. I would really appreciate your feedback. Thank you!

I would like to see some of your code.

If it’s something like this:

function returnSquared(num) {
  if (num === 2) return 4;
  if (num === 3) return 9;
  if (num === 5) return 25;

then I would say it’s cheating.

Thanks for the prompt reply @jenovs. Please see my code below for “Spinal Tap Case” Algo Intermediate challenge:
indent preformatted text by 4 spaces

    function spinalCase(str) {
        var strArr=str.split(" ");
        var finalStrArr=[];
        var indexCaps=[];
        var indexCaps=[0];  
        for(var i=1;i<word.length;i++){
           if(word[i]==word[i].toUpperCase() && word[i]!="-"){
         console.log("out",finalStrArr);    ,k){
          console.log("condition",element!=="" && k===0 && element[0]==element[0].toLowerCase());
        if(element!=="" && k===0 && element[0]==element[0].toLowerCase()){
            return element;        
        if(element!=="" && element[0]==element[0].toUpperCase()){
           return element[0].toLowerCase()+element.slice(1);
       else if(element!==""){
          return element;
         return element!==undefined && element!=="_";
         return finalStrArr.join("-");


I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

I really don’t understand what you’re saying here. Are you writing something, watching it fail, and changing the code until it passes? That’s so normal, I’m not sure what the alternative could be.

1 Like

^^this. IMO it’s not cheating as long as you learn from it and even then it’s still not cheating; if you aren’t learning why your code tweaks solve the requirements then you’re just selling yourself short.

No, that’s not cheating :slight_smile:

I would recommend you to sign up for and work on challenges there (start with 8kyu and 7kyu sorted by oldest) and after you finish a challenge look how others solved the same challenge (that’s why I recommend to start with oldest - they will have most solutions). You’ll quickly learn a lot of tricks how to solve these problems with much less code (my solution for this challenge is one line long :wink: )


lol what your doing sounds a lot like debugging. Every programmer worth their salt will debug and test the program to check output. how are you supposed to know if your program works if you don’t look at what it does?

One thing this style of programming takes away from is looking at the edge cases. When your writing code, your writing to pass the tests that you currently seeing, or you came up with. But you will not be able to imagine the edge cases that you didn’t create. You should rather be thinking about what it takes to break your code, and how you can strengthen it. Just a little lesson I’ve learned going about this whole thing.

1 Like

Yes, I am altering code so that it will give desired output.

Wow I wasnt really expecting so many replies guys. Thank you for all your advices I am glad to know that I am not cheating overall. Thanks guys! :slight_smile:

Google Test Driven Design (TDD) and you will find there is an entire methodology to developing applications with such an approach.


Yes this is basically what OP is doing, and what I have always been doing. TDD is what every developer should be doing, that is writing tests and then writing solutions for those tests.

I wouldn’t have made it much past my first “Hello World” program if I didn’t look at output and try to figure out why things weren’t working.

I expected this to be something like looking up answers in the wiki or asking for help on Stack Overflow, lol.

I am very new to programming, forgive my naivety. I kinda had an Impostor Syndrome for a while, that is why decided to make a post about it. Thanks! :slight_smile:

1 Like

It’s something we’ve all been through or going through! Don’t worry about it. If you need help, just ask or send a message, everyone is happy to help. As per your method, that’s not cheating, that’s being smart. Unless you are exploring the infinite possibilities of the universe and you don’t know the output, there will be some kind of hint of the output you would like, so why not write tests about it? Why not fiddle with the code and play around until you find a solution that fits your needs? That’s a real methodology, as stated by our campers friends in the comments; Test Driven Development, you develop writing tests for one or more cases and you build around the tests. In TDD you write a test to make it fail, then you write a solution to make it pass, no matter how stupid the solution is, then you write an elegant solution that makes it good.

1 Like

Dude, it is. Let me share my point of view. I always face problems as you. What I want to say : try write your algorithm than can be as simple as possible and can handle all possible test cases. For practice I really advice you Sort the problems by complexity and try to solve them one by one. After solving you can see other coder’s code and you be astonished how short code can be for that problem while you wrote ×2, ×3 lines more. This will definitely make you better at coding :slight_smile: