VOOZH about

URL: https://www.geeksforgeeks.org/blogs/how-to-begin-with-competitive-programming/

⇱ How to begin with Competitive Programming? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to begin with Competitive Programming?

Last Updated : 23 Jul, 2025

At the very beginning of competitive programming, barely anyone knew the coding style to be followed. Below is an example to help you understand how problems are crafted in competitive programming.

👁 competitive-programming

Let us consider below problem statement as an example. 

Problem Statement 

Linear Search: Given an integer array and an element x, find if element is present in array or not. If element is present, then print index of its first occurrence. Else print -1.

Input:

First line contains an integer, the number of test cases 'T'. Each test case should be an integer. Size of the array 'n' in the second line. In the third line, input the integer elements of the array in a single line separated by space. Element X should be input in the fourth line, i.e., after entering the elements of array. Repeat the above steps second line onwards for multiple test cases.

Output:

Print the output in a separate line returning the index of the element X. If the element is not present, then print -1.

Constraints:

1 <= T <= 100 

1 <= n <= 100 

1 <= arr[i] <= 100

Example Input and Output for Your Program

Input:
2
4
1 2 3 4
3
5
10 90 20 30 40
40
Output:
2
4

Explanation: 

There are 2 test cases (Note 2 at the beginning of input)
Test Case 1: Input: arr[] = {1, 2, 3, 4},
Element to be searched = 3.
Output: 2
Explanation: 3 is present at index 2.
Test Case 2: Input: arr[] = {10, 90, 20, 30, 40},
Element to be searched = 40.
Output: 4
Explanation: 40 is present at index 4.

Common mistakes by beginners

  1. Program should not print any extra character. Writing a statement like printf("Enter value of n") would cause rejection on any platform.
  2. Input and output format specifications must be read carefully. For example, most of the problems expect a new line after every output. So if we don't write printf("\n") or equivalent statement in a loop that runs for all test cases, the program would be rejected.

How to Begin Practice?

You can begin with above problem itself. Try submitting one of the above solutions here. It is recommended solve problems on Practice for cracking any coding interview.
Now you know how to write your first program in Competitive Programming Environment, you can start with School Practice Problems for Competitive Programming or Basic Practice Problems for Competitive Programming.

Platforms for practicing the Competitive Programming 

  • Codechef
  • Codeforces
  • HackerEarth
  • Leetcode
  • AtCoder
  • GeeksForGeeks
  • SPOJ
  • Project Euler

Must Read

Conclusion

In conclusion, competitive programming starts with understanding how to read and follow problem statements carefully. As shown in the linear search example, it's important to stick to the exact input and output formats without adding extra prompts or text. Small mistakes like missing a newline or printing unnecessary messages can lead to rejection. Beginners should focus on solving simple problems first to build confidence and learn the structure of coding challenges. Platforms like Codechef, Leetcode, and GeeksForGeeks offer a great place to practice and improve. With regular practice, anyone can develop strong problem-solving and coding skills.

Comment