The KODERUNNERS Community
The KODERUNNERS Community
• Competitive Coding 101
By : Sagnik Choudhury, Dipayan Ray and Avishek Das
The KODERUNNERS Community
What is Competitive Programming?
 Competitive programming is solving problems revolving around algorithms and data structures as
quickly as possible.
 Unlike other scenarios of programming, CP requires you to write code under various restrictions,
like execution time and memory limits for your program.
 Also, you are required to solve maximum number of problems in the stipulated time.
 These and all other restrictions make CP a great form of mind sport, and is an excellent way of
improving your programming skills.
 It is recognized and supported by almost all big tech companies like Google, Amazon, Facebook,
IBM and others.
Competitive Programming-101
The KODERUNNERS Community
What do these contests test?
 Algorithmic Skills
 Basic math skills
 Programming skills
 Speed (good typing speed helps)
 Creativity
 Debugging skills
Competitive Programming-101
The KODERUNNERS Community
How to get started?
 Understand Concept of Complexity (Time and Space both )in programs.
 Choose a programming language which you are more comfortable with.
 Learn about Data Structure , this is key , a lot of problems cannot be solved Without knowing Data
Structure (It's not just about algorithms and Arrays).
 Learn Different Programming paradigms , recursion, Dynamic Programming etc.
 Brush your basics .. Number theory, Modular arithmetic, Logarithmic Exponentiation etc.
Competitive Programming-101
The KODERUNNERS Community
Problem Properties:
 The correctness of an answer to the problem is absolute: it will be checked by computers, not
humans. No subjectiveness is present.
 The description contains a background story to hide the actual problem and to make it
interesting.Note that however, some problems have straightforward statement as well.
 Some examples of input/output will be given. This is so that we won't misunderstand the
input/output format and even the problem description itself.
 Ultimately, the problem is related to computer science, math, or logic. Hence, the solution can be
expressed algorithmically in a computer program.
Competitive Programming-101
The KODERUNNERS Community
Example I
 If the input format states something like:
“The first line of input gives the no. of test cases with each test case having 2
numbers n and m.”
then it would look something like this:
3
2 5
6 8
3 9
Competitive Programming-101
The KODERUNNERS Community
...contd.
And its C code would be like:
int a, b, c;
scanf(“%d”,&a);
while(a>0)
{ a--;
scanf(“%d %d”,&b,&c);
}
Competitive Programming-101
The KODERUNNERS Community
Example II
 Say you want to write a function to calculate x^4.
 We can simply solve this with:
z=x*x*x*x;
return z; //required 3 multiplication instructions.
 But a better solution will be:
z=x*x;
z=z*z;
return z; //required 2 multiplication instructions.
Competitive Programming-101
The KODERUNNERS Community
Where to practice?
Many Online Judges have problems of similar difficulty and similar environment. A list of such judges
are:-
 TopCoder
 SPOJ (SPhere Online Judge)
 CodeChef
 HackerRank
 HackerEarth
 Codefights
And many more...
Competitive Programming-101
The KODERUNNERS Community
Some Tips to CP
 Learning to code is all about practicing. Participate regularly in the programming contests. Solve
the ones that you cannot solve in the contest, after the contest. Apart from Topcoder and
Codeforces you can also look at HackerEarth Challenges or Codechef contests.
 Read the codes of highly rated programmers. Compare your solution with them. You can see that it
is simple and shorter than your solution. Analyze how they have approached and improve your
implementation skills.
 Read the editorials after the contest. You can learn how to solve the problems that you were not
able to solve in the contest and learn alternative ways to solve the problems which you could solve.
Competitive Programming-101
The KODERUNNERS Community
Some Tips, contd...
 Do not spend too much time if you are not getting the solution or are stuck somewhere.
 After you feel that you have spent enough time, look at the editorials. Understand the algorithm and
code it. Do not look at the real solution before you have attempted to write the code on your own.
 Programming is a very practical and hands-on skill. You have to continuously do it to be good at it.
It's not enough to solve the problem theoretically. You have to code it and get the solution
accepted. Knowing which algorithm/logic to use and implementing it are two different things. It
takes both to be good at programming.
 The programming learning phase is going to take a lot of time and the key is practicing regularly.
Do not give up on reading the editorials and implementing them even if it takes many hours/days.
Remember that everything requires practice to master it. Patience and Perseverance is the key
Competitive Programming-101
The KODERUNNERS Community
Why should you do it?
 Everyday skills. Problem solving, focus, time management, stress management, mental stamina,
etc.
 Specialized knowledge. Algorithms, AI, machine learning, computer vision, low-level optimization
and bunch of others.
 You are spending time on coding / debugging, of course these skills get better. (Surely other coding
types help too, but I'm not making comparison here)
 It enables you to think more clearly and properly
 Most importantly - Might help you in getting into Google, Facebook
Competitive Programming-101
The KODERUNNERS Community
Some Drawbacks
 Back Pain
 Back Pain
 Insomnia (sometimes when you're too serious!!)
 & Back Pain
Competitive Programming-101
The KODERUNNERS Community
Some Prestigious Contests:
 ACM – ICPC
 Google Code Jam
 Topcoder Open
 Facebook Hacker Cup
 IndiaHacks Programming Contest
Competitive Programming-101
The KODERUNNERS Community
Some Regular Contests:
 Week Of Code - HackerRank
 Monthly Easy - HackerEarth
 Monthly Circuit - HackerEarth
 101 Hack - HackerRank
 ProjectEuler+ - HackerRank (Indefinitely Open)
 CodeArena - HackerEarth (Head to Head and Indefinitely Open)
Competitive Programming-101
The KODERUNNERS Community
How Are The KIITians doing?
 https://www.hackerearth.com/college-ranking/
 https://www.hackerearth.com/@animesh7995
 http://www.hackerearth.com/@19soumik.rakshit96
 http://www.hackerearth.com/@aritradey97
 http://www.hackerearth.com/@csagnik.chaudhuri
Competitive Programming-101
The KODERUNNERS Community
Competitive Programming-101
LET'S START CODING!!!

Session 3 : Competitive programming 1

  • 1.
  • 2.
    The KODERUNNERS Community •Competitive Coding 101 By : Sagnik Choudhury, Dipayan Ray and Avishek Das
  • 3.
    The KODERUNNERS Community Whatis Competitive Programming?  Competitive programming is solving problems revolving around algorithms and data structures as quickly as possible.  Unlike other scenarios of programming, CP requires you to write code under various restrictions, like execution time and memory limits for your program.  Also, you are required to solve maximum number of problems in the stipulated time.  These and all other restrictions make CP a great form of mind sport, and is an excellent way of improving your programming skills.  It is recognized and supported by almost all big tech companies like Google, Amazon, Facebook, IBM and others. Competitive Programming-101
  • 4.
    The KODERUNNERS Community Whatdo these contests test?  Algorithmic Skills  Basic math skills  Programming skills  Speed (good typing speed helps)  Creativity  Debugging skills Competitive Programming-101
  • 5.
    The KODERUNNERS Community Howto get started?  Understand Concept of Complexity (Time and Space both )in programs.  Choose a programming language which you are more comfortable with.  Learn about Data Structure , this is key , a lot of problems cannot be solved Without knowing Data Structure (It's not just about algorithms and Arrays).  Learn Different Programming paradigms , recursion, Dynamic Programming etc.  Brush your basics .. Number theory, Modular arithmetic, Logarithmic Exponentiation etc. Competitive Programming-101
  • 6.
    The KODERUNNERS Community ProblemProperties:  The correctness of an answer to the problem is absolute: it will be checked by computers, not humans. No subjectiveness is present.  The description contains a background story to hide the actual problem and to make it interesting.Note that however, some problems have straightforward statement as well.  Some examples of input/output will be given. This is so that we won't misunderstand the input/output format and even the problem description itself.  Ultimately, the problem is related to computer science, math, or logic. Hence, the solution can be expressed algorithmically in a computer program. Competitive Programming-101
  • 7.
    The KODERUNNERS Community ExampleI  If the input format states something like: “The first line of input gives the no. of test cases with each test case having 2 numbers n and m.” then it would look something like this: 3 2 5 6 8 3 9 Competitive Programming-101
  • 8.
    The KODERUNNERS Community ...contd. Andits C code would be like: int a, b, c; scanf(“%d”,&a); while(a>0) { a--; scanf(“%d %d”,&b,&c); } Competitive Programming-101
  • 9.
    The KODERUNNERS Community ExampleII  Say you want to write a function to calculate x^4.  We can simply solve this with: z=x*x*x*x; return z; //required 3 multiplication instructions.  But a better solution will be: z=x*x; z=z*z; return z; //required 2 multiplication instructions. Competitive Programming-101
  • 10.
    The KODERUNNERS Community Whereto practice? Many Online Judges have problems of similar difficulty and similar environment. A list of such judges are:-  TopCoder  SPOJ (SPhere Online Judge)  CodeChef  HackerRank  HackerEarth  Codefights And many more... Competitive Programming-101
  • 11.
    The KODERUNNERS Community SomeTips to CP  Learning to code is all about practicing. Participate regularly in the programming contests. Solve the ones that you cannot solve in the contest, after the contest. Apart from Topcoder and Codeforces you can also look at HackerEarth Challenges or Codechef contests.  Read the codes of highly rated programmers. Compare your solution with them. You can see that it is simple and shorter than your solution. Analyze how they have approached and improve your implementation skills.  Read the editorials after the contest. You can learn how to solve the problems that you were not able to solve in the contest and learn alternative ways to solve the problems which you could solve. Competitive Programming-101
  • 12.
    The KODERUNNERS Community SomeTips, contd...  Do not spend too much time if you are not getting the solution or are stuck somewhere.  After you feel that you have spent enough time, look at the editorials. Understand the algorithm and code it. Do not look at the real solution before you have attempted to write the code on your own.  Programming is a very practical and hands-on skill. You have to continuously do it to be good at it. It's not enough to solve the problem theoretically. You have to code it and get the solution accepted. Knowing which algorithm/logic to use and implementing it are two different things. It takes both to be good at programming.  The programming learning phase is going to take a lot of time and the key is practicing regularly. Do not give up on reading the editorials and implementing them even if it takes many hours/days. Remember that everything requires practice to master it. Patience and Perseverance is the key Competitive Programming-101
  • 13.
    The KODERUNNERS Community Whyshould you do it?  Everyday skills. Problem solving, focus, time management, stress management, mental stamina, etc.  Specialized knowledge. Algorithms, AI, machine learning, computer vision, low-level optimization and bunch of others.  You are spending time on coding / debugging, of course these skills get better. (Surely other coding types help too, but I'm not making comparison here)  It enables you to think more clearly and properly  Most importantly - Might help you in getting into Google, Facebook Competitive Programming-101
  • 14.
    The KODERUNNERS Community SomeDrawbacks  Back Pain  Back Pain  Insomnia (sometimes when you're too serious!!)  & Back Pain Competitive Programming-101
  • 15.
    The KODERUNNERS Community SomePrestigious Contests:  ACM – ICPC  Google Code Jam  Topcoder Open  Facebook Hacker Cup  IndiaHacks Programming Contest Competitive Programming-101
  • 16.
    The KODERUNNERS Community SomeRegular Contests:  Week Of Code - HackerRank  Monthly Easy - HackerEarth  Monthly Circuit - HackerEarth  101 Hack - HackerRank  ProjectEuler+ - HackerRank (Indefinitely Open)  CodeArena - HackerEarth (Head to Head and Indefinitely Open) Competitive Programming-101
  • 17.
    The KODERUNNERS Community HowAre The KIITians doing?  https://www.hackerearth.com/college-ranking/  https://www.hackerearth.com/@animesh7995  http://www.hackerearth.com/@19soumik.rakshit96  http://www.hackerearth.com/@aritradey97  http://www.hackerearth.com/@csagnik.chaudhuri Competitive Programming-101
  • 18.
    The KODERUNNERS Community CompetitiveProgramming-101 LET'S START CODING!!!

Editor's Notes

  • #3 Hands on : Creative Coding ; Perlin Noise : MineCraft , Data Analysis : Bar Graph,