The Wayback Machine - https://web.archive.org/web/20240831204235/https://www.geeksforgeeks.org/frequency-measurement-techniques-for-competitive-programming/
Open In App

Frequency Measuring Techniques for Competitive Programming

Last Updated : 15 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Measuring the frequency of elements in an array is a really handy skill and is required a lot of competitive coding problems. We, in a lot of problems, are required to measure the frequency of various elements like numbers, alphabets, symbols, etc. as a part of our problem.

Examples:  

Input:  arr[] = {10, 20, 20, 10, 10, 20, 5, 20}
Output: 10 3
         20 4
         5  1

Input: arr[] = {10, 20, 20}
Output: 10 2
         20 1

Naive method: We run two loops. For every item count number of times, it occurs. To avoid duplicate printing, keep track of processed items. 

Implementation:

C++





Java




// Java program to count frequencies
// of array items
import java.util.*;
 
class GFG
{
static void countFreq(int arr[], int n)
{
    // Mark all array elements as not visited
    boolean []visited = new boolean[n];
 
    // Traverse through array elements and
    // count frequencies
    for (int i = 0; i < n; i++)
    {
 
        // Skip this element if already processed
        if (visited[i] == true)
            continue;
 
        // Count frequency
        int count = 1;
        for (int j = i + 1; j < n; j++)
        {
            if (arr[i] == arr[j])
            {
                visited[j] = true;
                count++;
            }
        }
        System.out.println(arr[i] + " " + count);
    }
}
 
// Driver Code
public static void main(String[] args)
{
    int arr[] = { 10, 20, 20, 10, 10, 20, 5, 20 };
    int n = arr.length;
    countFreq(arr, n);
}
}
 
// This code is contributed by 29AjayKumar


Python3





C#





Javascript




<script>
    // Javascript program to count frequencies of array items
     
    function countFreq(arr, n)
    {
        // Mark all array elements as not visited
        let visited = new Array(n);
        visited.fill(false);
 
        // Traverse through array elements and
        // count frequencies
        for (let i = 0; i < n; i++) {
 
            // Skip this element if already processed
            if (visited[i] == true)
                continue;
 
            // Count frequency
            let count = 1;
            for (let j = i + 1; j < n; j++) {
                if (arr[i] == arr[j]) {
                    visited[j] = true;
                    count++;
                }
            }
            document.write(arr[i] + " " + count + "</br>");
        }
    }
 
    let arr = [ 10, 20, 20, 10, 10, 20, 5, 20 ];
    let n = arr.length;
    countFreq(arr, n);
     
    // This code is contributed by mukesh07.
</script>


Output

10 3
20 4
5 1

Time Complexity: O(n*n)
Auxiliary Space: O(n)

Optimized methods :

Measuring frequencies when elements are limited by value: If our input array has small values, we can use array elements as index in a count array and increment count. In below example, elements are maximum 10. 

Input :  arr[] = {5, 5, 6, 6, 5, 6, 1, 2, 3, 10, 10}
         limit = 10
Output : 1 1
         2 1
         3 1
         5 3
         6 3
         10 2

Implementation:

C++





Java





Python3





C#





Javascript





Output

1 1
2 1
3 1
5 3
6 3
10 2

Time Complexity: O(n+k) where n is the size of the input array and k is the limit value.
Auxiliary Space: O(k).

Implementation:

C++





Java





Python3





C#





Javascript




<script>
 
// Javascript program to count frequencies of array items
     
    let limit = 255;
     
function countFreq(str)
{
        // Create an array to store counts. The size
    // of array is limit+1 and all values are
    // initially 0
    let count= new Array(limit + 1);
    for(let i=0;i<count.length;i++)
    {
        count[i]=0;
    }
  
    // Traverse through string characters and
    // count frequencies
    for (let i = 0; i < str.length; i++)
        count[str[i].charCodeAt(0)]++;
  
    for (let i = 0; i <= limit; i++)
    {    if (count[i] > 0)
            document.write(String.fromCharCode(i) + " " + count[i]+"<br>");
    }
}
 
// Driver Code
let str = "GeeksforGeeks";
countFreq(str);
     
     
    // This code is contributed by unknown2108
</script>


Output

G 2
e 4
f 1
k 2
o 1
r 1
s 2

Measuring frequencies when elements are in limited range: For example, consider a string containing only upper case alphabets. Elements of string are limited in range from ‘A’ to ‘Z’. The idea is to subtract smallest element (‘A’ in this example) to get the index of the element. 

Implementation:

C++




// C++ program to count frequencies of array items
#include <bits/stdc++.h>
using namespace std;
 
const int limit = 25;
 
void countFreq(string str)
{
    // Create an array to store counts. The size
    // of array is limit+1 and all values are
    // initially 0
    vector<int> count(limit+1, 0);
  
    // Traverse through string characters and
    // count frequencies
    for (int i = 0; i < str.length(); i++)
        count[str[i] - 'A']++;
  
    for (int i = 0; i <= limit; i++)
       if (count[i] > 0)
        cout << (char)(i + 'A') << " " << count[i] << endl;
     
}
  
int main()
{
    string str = "GEEKSFORGEEKS";
    countFreq(str);
    return 0;
}


Java




// Java program to count frequencies
// of array items
import java.util.*;
 
class GFG
{
static int limit = 25;
 
static void countFreq(String str)
{
    // Create an array to store counts.
    // The size of array is limit+1 and
    // all values are initially 0
    int []count = new int[limit + 1];
 
    // Traverse through string characters
    // and count frequencies
    for (int i = 0; i < str.length(); i++)
        count[str.charAt(i) - 'A']++;
 
    for (int i = 0; i <= limit; i++)
    if (count[i] > 0)
        System.out.println((char)(i + 'A') +
                           " " + count[i]);
}
 
// Driver Code
public static void main(String[] args)
{
    String str = "GEEKSFORGEEKS";
    countFreq(str);
}
}
 
// This code is contributed by PrinciRaj1992


Python3




# Python3 program to count frequencies of array items
limit = 25;
def countFreq(str):
     
    # Create an array to store counts. The size
    # of array is limit+1 and all values are
    # initially 0
    count = [0 for i in range(limit + 1)]
   
    # Traverse through string characters and
    # count frequencies
    for i in range(len(str)):  
        count[ord(str[i]) - ord('A')] += 1
   
    for i in range(limit + 1):
       if (count[i] > 0):
           print(chr(i + ord('A')), count[i])
 
# Driver code
if __name__=='__main__':
     
    str = "GEEKSFORGEEKS";
    countFreq(str);
     
# This code is contributed by Pratham76


C#




// C# program to count frequencies
// of array items
using System;
     
class GFG
{
static int limit = 25;
  
static void countFreq(String str)
{
    // Create an array to store counts.
    // The size of array is limit+1 and
    // all values are initially 0
    int []count = new int[limit + 1];
  
    // Traverse through string characters
    // and count frequencies
    for (int i = 0; i < str.Length; i++)
        count[str[i] - 'A']++;
  
    for (int i = 0; i <= limit; i++)
    if (count[i] > 0)
        Console.WriteLine((char)(i + 'A') +
                           " " + count[i]);
}
  
// Driver Code
public static void Main(String[] args)
{
    String str = "GEEKSFORGEEKS";
    countFreq(str);
}
}
  
// This code contributed by PrinciRaj1992


Javascript




<script>
 
// JavaScript program to count frequencies
// of array items
 
let limit = 25;
function countFreq(str)
{
    // Create an array to store counts.
    // The size of array is limit+1 and
    // all values are initially 0
    let count = new Array(limit + 1);
    for(let i=0;i<limit+1;i++)
    {
        count[i]=0;
    }
  
    // Traverse through string characters
    // and count frequencies
    for (let i = 0; i < str.length; i++)
        count[str[i].charCodeAt(0) - 'A'.charCodeAt(0)]++;
  
    for (let i = 0; i <= limit; i++)
    if (count[i] > 0)
        document.write(String.fromCharCode(i + 'A'.charCodeAt(0)) +
                           " " + count[i]+"<br>");
}
 
// Driver Code
let str = "GEEKSFORGEEKS";
countFreq(str);
 
// This code is contributed by rag2127
 
</script>


Output

E 4
F 1
G 2
K 2
O 1
R 1
S 2

Measuring frequencies if no range and no limit: The idea is to use hashing (unordered_map in C++ and HashMap in Java) to get frequencies. 

Implementation:

C++




// C++ program to count frequencies of array items
#include <bits/stdc++.h>
using namespace std;
 
void countFreq(int arr[], int n)
{
    unordered_map<int, int> mp;
 
    // Traverse through array elements and
    // count frequencies
    for (int i = 0; i < n; i++)
        mp[arr[i]]++;
 
    // Traverse through map and print frequencies
    for (auto x : mp)
        cout << x.first << " " << x.second << endl;
}
 
int main()
{
    int arr[] = { 10, 20, 20, 10, 10, 20, 5, 20 };
    int n = sizeof(arr) / sizeof(arr[0]);
    countFreq(arr, n);
    return 0;
}


Java




// Java program to count frequencies of array items
import java.util.*;
class GFG
{
static void countFreq(int arr[], int n)
{
    HashMap<Integer,
            Integer>mp = new HashMap<Integer,
                                     Integer>();
                                      
    // Traverse through array elements and
    // count frequencies
    for (int i = 0 ; i < n; i++)
    {
        if(mp.containsKey(arr[i]))
        {
            mp.put(arr[i], mp.get(arr[i]) + 1);
        }
        else
        {
            mp.put(arr[i], 1);
        }
    }
     
    // Traverse through map and print frequencies
    for (Map.Entry<Integer,
                   Integer> entry : mp.entrySet())
        System.out.println(entry.getKey() + " " +
                           entry.getValue());
}
 
// Driver Code
public static void main(String[] args)
{
    int arr[] = { 10, 20, 20, 10, 10, 20, 5, 20 };
    int n = arr.length;
    countFreq(arr, n);   
}
}
 
// This code is contributed by 29AjayKumar


Python3




# Python3 program to count frequencies of array items
def countFreq(arr, n):
 
    mp = {}
  
    # Traverse through array elements and
    # count frequencies
    for i in range(n):
        if arr[i] in mp:
            mp[arr[i]] += 1
        else:
            mp[arr[i]] = 1
  
    # Traverse through map and print frequencies
    for x in sorted(mp):
        print(x, mp[x])
 
# Driver Code
arr = [ 10, 20, 20, 10, 10, 20, 5, 20 ]
n = len(arr)
 
countFreq(arr, n)
 
# This code is contributed by divyesh072019


C#




// C# program to count frequencies of array items
using System;
using System.Collections.Generic;
 
class GFG
{
static void countFreq(int []arr, int n)
{
    Dictionary<int,
               int> mp = new Dictionary<int,
                                        int>();
                                     
    // Traverse through array elements and
    // count frequencies
    for (int i = 0 ; i < n; i++)
    {
        if(mp.ContainsKey(arr[i]))
        {
            var val = mp[arr[i]];
            mp.Remove(arr[i]);
            mp.Add(arr[i], val + 1);
        }
        else
        {
            mp.Add(arr[i], 1);
        }
    }
     
    // Traverse through map and print frequencies
    foreach(KeyValuePair<int, int> entry in mp)
        Console.WriteLine(entry.Key + " " +
                          entry.Value);
}
 
// Driver Code
public static void Main(String[] args)
{
    int []arr = { 10, 20, 20, 10,
                  10, 20, 5, 20 };
    int n = arr.Length;
    countFreq(arr, n);
}
}
 
// This code is contributed by Princi Singh


Javascript




<script>
// Javascript program to count frequencies of array items
function  countFreq(arr, n)
{
    let mp = new Map();
                                       
    // Traverse through array elements and
    // count frequencies
    for (let i = 0 ; i < n; i++)
    {
        if(mp.has(arr[i]))
        {
            mp.set(arr[i], mp.get(arr[i]) + 1);
        }
        else
        {
            mp.set(arr[i], 1);
        }
    }
      
    // Traverse through map and print frequencies
    for (let [key, value] of mp.entries())
        document.write(key + " " +
                           value+"<br>");
}
 
// Driver Code
let arr=[10, 20, 20, 10, 10, 20, 5, 20];
let n = arr.length;
countFreq(arr, n);  
 
// This code is contributed by ab2127
</script>


Output

5 1
20 4
10 3

Complexity Analysis:

  • Time Complexity : O(n) 
  • Auxiliary Space : O(n)

In above efficient solution, how to print elements in same order as they appear in input?  

Implementation:

C++




// C++ program to count frequencies of array items
#include <bits/stdc++.h>
using namespace std;
 
void countFreq(int arr[], int n)
{
    unordered_map<int, int> mp;
 
    // Traverse through array elements and
    // count frequencies
    for (int i = 0; i < n; i++)
        mp[arr[i]]++;
 
    // To print elements according to first
    // occurrence, traverse array one more time
    // print frequencies of elements and mark
    // frequencies as -1 so that same element
    // is not printed multiple times.
    for (int i = 0; i < n; i++) {
      if (mp[arr[i]] != -1)
      {
          cout << arr[i] << " " << mp[arr[i]] << endl;
          mp[arr[i]] = -1;
      }
    }
}
 
int main()
{
    int arr[] = { 10, 20, 20, 10, 10, 20, 5, 20 };
    int n = sizeof(arr) / sizeof(arr[0]);
    countFreq(arr, n);
    return 0;
}


Java




// Java program to count frequencies of array items
import java.util.*;
 
class GFG
{
static void countFreq(int arr[], int n)
{
    HashMap<Integer,
            Integer> mp = new HashMap<Integer,
                                      Integer>();
 
    // Traverse through array elements and
    // count frequencies
    for (int i = 0 ; i < n; i++)
    {
        if(mp.containsKey(arr[i]))
        {
            mp.put(arr[i], mp.get(arr[i]) + 1);
        }
        else
        {
            mp.put(arr[i], 1);
        }
    }
     
    // To print elements according to first
    // occurrence, traverse array one more time
    // print frequencies of elements and mark
    // frequencies as -1 so that same element
    // is not printed multiple times.
    for (int i = 0; i < n; i++)
    {
        if (mp.get(arr[i]) != -1)
        {
            System.out.println(arr[i] + " " +
                               mp.get(arr[i]));
            mp. put(arr[i], -1);
        }
    }
}
 
// Driver Code
public static void main(String[] args)
{
    int arr[] = { 10, 20, 20, 10, 10, 20, 5, 20 };
    int n = arr.length;
    countFreq(arr, n);
}
}
 
// This code is contributed by Princi Singh


Python3




# Python3 program to count frequencies of array items
def countFreq(arr, n):
    mp = {}
     
    # Traverse through array elements and
    # count frequencies
    for i in range(n):
        if arr[i] not in mp:
            mp[arr[i]] = 1
        else:
            mp[arr[i]] += 1
 
    # To print elements according to first
    # occurrence, traverse array one more time
    # print frequencies of elements and mark
    # frequencies as -1 so that same element
    # is not printed multiple times.
    for i in range(n):
        if(mp[arr[i]] != -1):
            print(arr[i], mp[arr[i]])
            mp[arr[i]] = -1
 
# Driver code
arr = [10, 20, 20, 10, 10, 20, 5, 20 ]
n = len(arr)
countFreq(arr, n)
 
# This code is contributed by rag2127


C#




// C# program to count frequencies of array items
using System;
using System.Collections.Generic;
     
class GFG
{
static void countFreq(int []arr, int n)
{
    Dictionary<int,
               int> mp = new Dictionary<int,
                                        int>();
 
    // Traverse through array elements and
    // count frequencies
    for (int i = 0 ; i < n; i++)
    {
        if(mp.ContainsKey(arr[i]))
        {
            mp[arr[i]] = mp[arr[i]] + 1;
        }
        else
        {
            mp.Add(arr[i], 1);
        }
    }
     
    // To print elements according to first
    // occurrence, traverse array one more time
    // print frequencies of elements and mark
    // frequencies as -1 so that same element
    // is not printed multiple times.
    for (int i = 0; i < n; i++)
    {
        if (mp[arr[i]] != -1)
        {
            Console.WriteLine(arr[i] + " " +
                              mp[arr[i]]);
            mp[arr[i]] = - 1;
        }
    }
}
 
// Driver Code
public static void Main(String[] args)
{
    int []arr = { 10, 20, 20, 10,
                  10, 20, 5, 20 };
    int n = arr.Length;
    countFreq(arr, n);
}
}
 
// This code is contributed by Rajput-Ji


Javascript




<script>
 
// Javascript program to count
// frequencies of array items
function countFreq(arr, n)
{
    let mp = new Map();
  
    // Traverse through array elements and
    // count frequencies
    for(let i = 0 ; i < n; i++)
    {
        if (mp.has(arr[i]))
        {
            mp.set(arr[i], mp.get(arr[i]) + 1);
        }
        else
        {
            mp.set(arr[i], 1);
        }
    }
      
    // To print elements according to first
    // occurrence, traverse array one more time
    // print frequencies of elements and mark
    // frequencies as -1 so that same element
    // is not printed multiple times.
    for(let i = 0; i < n; i++)
    {
        if (mp.get(arr[i]) != -1)
        {
            document.write(arr[i] + " " +
                    mp.get(arr[i]) + "<br>");
            mp.set(arr[i], -1);
        }
    }
}
 
// Driver Code
let arr = [ 10, 20, 20, 10, 10, 20, 5, 20 ];
let n = arr.length;   
 
countFreq(arr, n);
 
// This code is contributed by patel2127
 
</script>


Output

10 3
20 4
5 1

Complexity Analysis

  • Time Complexity : O(n) 
  • Auxiliary Space : O(n)

In Java, we can get elements in same order using LinkedHashMap. Therefore we do not need an extra loop.

Lot of problems are based on frequency measurement and will be a cheesecake if we know how to calculate frequency of various elements in a given array. For example try the given below problems which are based on frequency measurement: 

  1. Anagrams
  2. Sorting Elements of an Array by Frequency
  3. Single Number

 



Previous Article
Next Article

Similar Reads

Precomputation Techniques for Competitive Programming
What is the Pre-Computation Technique?Precomputation refers to the process of pre-calculating and storing the results of certain computations or data structures in advance, in order to speed up the execution time of a program. This can be useful in situations where the same calculations or data structures are needed multiple times, as it avoids the
15+ min read
Tips and Tricks for Competitive Programmers | Set 2 (Language to be used for Competitive Programming)
This is a question asked quite often as in which language should be preferred to be efficient in competitive programming. It is something one should not worry about as what matters is the logic, not the language. Most of the languages are more or less same, but till now the most preferred language is C++, and here are the reasons. Python Simple and
5 min read
Competitive Programming vs General Programming
Programming enthusiasts face a crossroads - Competitive Programming or General Programming? This article sheds light on the distinctions between Competitive Programming vs General Programming, offering a quick guide for those navigating the coding landscape. Whether you're aiming for speed and precision in competitions or tackling real-world projec
3 min read
Dynamic Programming in Game Theory for Competitive Programming
In the fast-paced world of competitive programming, mastering dynamic programming in game theory is the key to solving complex strategic challenges. This article explores how dynamic programming in game theory can enhance your problem-solving skills and strategic insights, giving you a competitive edge. Whether you're a seasoned coder or a newcomer
15+ min read
Top Programming Languages For Competitive Programming
Building an application, running a server, or even implementing a game needs a programming language as the foundation. There are almost more than 700 programming languages which are the most popular ones and this number will increase day by day. But, you don't need to learn all of them. Having a good command of anyone is enough for you to grow your
13 min read
Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
Given two strings, the task is to check whether the frequencies of a character(for each character) in one string are multiple or a factor in another string. If it is, then output "YES", otherwise output "NO". Examples: Input: s1 = "aabccd", s2 = "bbbaaaacc" Output: YES Frequency of 'a' in s1 and s2 are 2 and 4 respectively, and 2 is a factor of 4 F
6 min read
Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
Given a string S, the task is to find the prefix of string S with the maximum possible length such that frequency of each character in the prefix is at most the number of characters in S with minimum frequency. Examples: Input: S = 'aabcdaab' Output: aabcd Explanation: Frequency of characters in the given string - {a: 4, b: 2, c: 1, d: 1} Minimum f
8 min read
Count of Binary Strings of length N such that frequency of 1's exceeds frequency of 0's
Given an integer N, the task is to find the number of Binary Strings of length N such that frequency of 1's is greater than the frequency of 0's. Example: Input: N = 2Output: 1Explanation: Count of binary strings of length 2 is 4 i.e. {"00", "01", "10", "11"}. The only string having frequency of 1's greater than that of 0's is "11". Input: N = 3Out
8 min read
Maximum difference between frequency of two elements such that element having greater frequency is also greater
Given an array of n positive integers with many repeating elements. The task is to find the maximum difference between the frequency of any two different elements, such that the element with greater frequency is also greater in value than the second integer. Examples: Input : arr[] = { 3, 1, 3, 2, 3, 2 }. Output : 2 Frequency of 3 = 3. Frequency of
12 min read
How to read Competitive Programming Questions?
Competitive Programming is considered as a sport in the field of computer science. The culture of this sport is growing day by day and a lot of people are also considering this as a career choice. So, to help the participants with improving their efficiency in this sport, in this post, we have tried to cover all possible things, needed to keep in m
5 min read
Some useful C++ tricks for beginners in Competitive Programming
Here are some of the basic C++ tricks that every beginner in Competitive Programming should follow for increased speed. However, competitive programming can only be mastered with time and lots of practice. These tricks will just help you to save a little time during the contests which sometimes matters a lot. Using the auto keyword to declare data
3 min read
Importance of Testing In Competitive Programming
Many times while solving problems, we face issues like time limit exceeds, wrong solution, runtime error, and memory limit exceeds because after designing algorithm we don't test algorithm efficiency, correctness, time complexity and running the algorithm on a large set of inputs for testing purpose. This is where stress testing comes for rescue. S
3 min read
Writing code faster during Competitive Programming in C++
This article focuses on how to implement your solutions and implement them fast while doing competitive programming. Setup Please refer Setting up a C++ Competitive Programming Environment Snippets Snippet is a programming term for a small region of re-usable source Code. A lot of modern text editors like Sublime provide you a functionality to auto
3 min read
Mathematics Tricks For Competitive Programming In Python 3
Here are some of the exciting features that Python 3.8 provides for programmers in competitive programming. These new features are related to some math functions and algorithms that are frequently used by competitive programmers. The implementation of these features has the time complexity which is the same in case of a program when implemented fro
3 min read
Competitive Programming vs Software Development - Where Should I Invest My Time?
Competitive Programming....what comes to your mind first...? most probably you associate the idea of solving the coding questions on GeeksforGeeks, Codechef, Topcoder, Codeforces, Hackerrank, etc. What about Software Development...? Most probably you imagine a person building an application, a website, mobile apps, or a person handling some backend
11 min read
5 Best Languages for Competitive Programming
Needless to say, Competitive Programming is one of the most crucial and popular aspects of a programmer's journey. Though, all the programmers are strongly recommended to participate in such coding challenges to enhance their coding skills and to get various ravishing prizes, rewards, and other career opportunities. Meanwhile, there's a question th
5 min read
Fast I/O for Competitive Programming in Python
In Competitive Programming, it is important to read input as fast as possible to save valuable time. Input/Output in Python can be sometimes time taking in cases when the input is huge or to output any numbers of lines or a huge number of arrays(lists) line after line. Fast Input Normally, the input is taken from STDIN in the form of String using i
3 min read
How to get started with Competitive Programming in JavaScript
Competitive programming is a popular activity among programmers looking to enhance their problem-solving skills and algorithmic thinking. JavaScript is a wonderful language for competitive programming because of how simple it is to use, how powerful its libraries are, and how quickly it can prototype ideas. JavaScript is a great option for programm
5 min read
Why Java Language is Slower Than CPP for Competitive Programming?
Choosing the appropriate language while starting competitive programming is the most important factor. Generally, we choose that language that has short syntax and executes very fast or which is familiar to us, and we know all the working patterns of that particular whether it is Java or C++. Most of the programmers use C++ for competitive programm
5 min read
Points to focus on while doing Competitive Programming
Competitive Programming is vital for one’s development in the coding field. This article is going to discuss some basics points one should keep in mind while competing. Make a list of functions to perform tasks that are encountered frequently in questions and add them to your code in the form of a template. This saves time during contests and helps
5 min read
How to Use int as long long int for Competitive Programming?
Most of the time, input constraints in Competitive programming questions are bigger than the limits of int. Therefore, there is a need to use long int or even long long int. Here let us take two cases so that if a naive user writes correct logic still input is not getting accepted can get to know where the rectification is required. Case 1: Big int
3 min read
Java Generics to Code Efficiently in Competitive Programming
Templates are the foundation of generic programming, which involve writing code in a way that is independent of any particular type. These powerful tools can be used for writing our code effectively. Some cool tricks that may be used in Competitive Programming are given as follows: Fast Input/Output: This uses the time advantage of BufferedReader a
9 min read
Setting up Java Competitive Programming Environment
An operating system is required to be installed on your system. here we will be discussing the setup in windows. However, you can choose any operating system. Install JDK (Java Development Kit) JDK, is a program that allows you to write Java code from the comfort of your desktop. It contains a variety of tools that are very useful for creating, run
5 min read
Creation and Utilisation of Custom Snippets for Competitive programming in VScode
Coding down the whole algorithm from scratch during the online contest can cost you plenty of time and may lead to a bad rank. There is no point in coding the same algorithm you have coded hundreds of times earlier. Why not utilize your previously coded implementations? You can do that by creating custom code snippets and summoning them just by a k
2 min read
Java Competitive Programming Setup in VS Code with Fast I/O and Snippets
Though C++ is the dominating language in the competitive programming universe, there is a fair share of users who still continue to use Java as it has been there seen in the development arena and at the same time can be used competitive programming being fast as it can be toggled to and from where python being slowest among dynamic is hardly seen i
8 min read
Most Critical Mistakes &amp; Tips in Competitive Programming
The moment a beginner hears this word, an image pops up in one's mind where students are sitting in a room full of Computers and coding some out of the world stuff, We'll to be honest it's nothing too hard to grasp so we will be proposing tips that help a programmer to level up faster. So let's begin with the most underrated points on each topic wh
15+ min read
What are Ad Hoc Problems in Competitive Programming?
The Ad Hoc problems are problems that cannot be classified anywhere else in the categories with well-studied solutions since each problem description and its corresponding solution are unique. These problems don't fall under standard categories, there is no specific or general technique exists to solve them. Many Ad Hoc problems are easy, but this
5 min read
Is Competitive Programming Must For Software Development Roles?
Competitive Programming is a mental sport that involves programmers competing against each other within the given time limit. It makes your problem-solving and coding skills better and efficient - also, it provides you with an edge over other candidates during the tech interviews. It makes you an amazing problem solver which is important in softwar
5 min read
What are Online and Offline query-based questions in Competitive Programming
The query-based questions of competitive programming are mainly of two types: Offline Query.Online Query. Offline Query An offline algorithm allows us to manipulate the data to be queried before any answer is printed. This is usually only possible when the queries do not update the original element set before printing the result. Features: Offline
4 min read
Top 10 Most Used Inbuilt C++ functions for Competitive Programming
In this article, we will discuss about the 10 most used inbuilt functions of C++ which will help you to save time and make code concise as well during competitive programming. List of top 10 inbuilt functions in C++ pow()sqrt()min()max()swap()gcd()toupper()tolower()floor()ceil()1. pow( ) This function helps to find the value of a number raised to a
7 min read