A Hitchhiker's Guide to Asking Questions!

As a beginner , intermediate or experienced coder , it’s quite natural to have doubts regarding a question , problem statement , test cases or approach so I thought I’d come up with a few guidelines , by no means are these hard and fast rules , just my opinion :slight_smile: :

  1. Make sure that the problem is not from an ongoing contest !
  2. If you plan to include code in your question , please format the code like @ssjgz always reminds us that the forum software has mangled the code;) . It really isn’t that hard : Three backticks (```) before code and three after the code should do the trick
    #include <bits/stdc++.h>
    using namespace std ; 
    int main()
    {
        //Pretty colors and formatted code , here we come 
        return 0  ;
    }
  1. Try to use meaningful variable names and clean code . Nobody is going to benefit from obfuscated code , I’ve read codes where variables were named after ahem cuss words and while you’re free to name it (whatever suits your fancy) , while asking for help , it’s better if understandable
  2. Provide Context -
    i. Link to the problem statement , it makes it easier for people to read and understand the problem , get initial bearings , understand the sample input and you’ll get help faster
    ii. Provide a brief write-up demonstrating what you’ve tried so far and what exactly you need help with , makes it so much better than a generic “Help Me! Fast”
  3. Check if an Editorial exists , if it does and you’re stuck , read it and try to understand it , maybe read the hints and give the problem a try again , maybe you’ll solve this and the green tick will be yours :slight_smile:. Google or check the forum if your question has already been answered!
    (TB to every time a post was made asking why the fully solved problem appeared as partially solved)
  4. There’s a nice policy on Quora , Be Nice Be Respectful (BNBR) , I think it applies here too and I hold the opinion that both the OP and the persons who respond have to be respectful to one another , ill-language and trashing someone does not help and has quite the opposite effect.
  5. There are many posts stating that the test cases are wrong , mostly by people starting out , the chance of that in an official contest is I’d say very low . Something like getting heads five times in a row on tossing an unbiased coin. Possible , yes but rare . The problem might unfortunately be with your logic :((
  6. If you are getting a wrong answer , check the constraints , identify the corner cases where you think your program / logic might fail and try again . In case of a TLE , try to come up with a solution with better complexity , if you have Seg Fault , check for array out of bounds etc.
  7. There isn’t a certainty that someone with a rating higher than you always has the right answer to your solution , read all the answers and find out what best suits your needs and maybe say a thank you if possible ? Small tokens of appreciation go a long way .
  8. I don’t mind tagging people (once), I’ve seen a lot of people tagging @vijju123 , @ssjgz , @tmwilliamlin , @everule1 etc. (and others who are on the top contributors list?) which is understandable as they do help the most people , but don’t force people , you have to wait , be patient , it likely will take some time before your query is resolved and tagging people repeatedly with imperative statements gets annoying :slight_smile: People who willingly take up a moment of their time to answer your question diligently in the best possible way !

Let me know if you agree or disagree with these or if you have some more you’d like me to add :slight_smile:
Stay Safe!
Happy Coding!

49 Likes

One more thing I find a lot useful is finding test cases(for which your solution gives the wrong answer) using AC solutions present in submissions
Using tc generator generate small random test cases.
Now run these test cases on both the solutions and check the output difference, if there is no difference after few tc then there might be overflow problem.

7 Likes

Good Point! Also useful when you have a brute force solution to the problem but are not sure why the optimised logic fails.
Write a code to generate Test Cases randomly (Tc can be small so that it’s easy to debug)
Maybe try something simple like :

while(true) 
{
//Generate testCase
if(bruteForce(testCase)!=optimisedLogic(testCase)) 
{
          //print testCase 
           break ;
}
}
     

You can have a look at @ssjgz’s random test case generator , he’s posted it on discuss or have a look at @errichto’s video on the topic : How to test your solution?

Update : The test case generator I linked seems to be unavailable right now :((
This Codeforces Blog specifies ways to use testlib :slight_smile:

4 Likes