Browse Categories
Choose your Categories to read
Competitive Programming
The three major programming languages used in Competitive Programming are C++, Java, and Python. Each language has its own pros and cons. Some of them are mentioned below: C++: Pros- Takes very less execution time. Cons- It doesn't support some necessary functions. For example, it doesn't support decrease-key operation in the case of priority_queues. Java: Pros- Faster than python but slower than C++. Cons- Code becomes lengthy. Python: Pros- Code becomes very short, with various built-in functions available. Cons- Requires too much time for execution. The major competitive programming-based website is Codeforces in which generally around 15,000 participants participate in a contest. Every website has levels that can be in the form of stars, positions (like a specialist, expert, master, grandmaster, etc), or simply numerical rating.
Recursion and Backtracking
If you’ve seen the movie inception, you’ll understand recursion easily. In the movie, Leonardo had a dream, in that dream he had another dream in that dream he had yet another dream, and that goes on. So it’s like there is a function called dream(), that’s being called over and over in itself. This is what recursion is. is useful in solving problems that can be broken down into smaller problems of the same type. Now, suppose you’re very hungry and wish to eat laddoos. There are three restaurants in front of you and someone already told you that only one restaurant sells laddoos. So what should you do? You first go to the first restaurant, check if laddoo is available there. If yes, eat it and you’re done. Otherwise, come out of the first restaurant, move on to the next restaurant, and check if it’s available there. If yes, eat it and you’re done. If not, you come out of the second restaurant also and move to the third one. That must be selling laddoos as one of the restaurants is surely selling laddoos. This is backtracking. So basically in backtracking we attempt solving a subproblem, and if we don't reach the desired solution, then undo whatever we did for solving that subproblem, and try solving another subproblem.
Recursion
When we repeat a similar process many times, it is known as Recursion. In Recursion, a function calls itself many times till it hits some base case, m
Divide and Conquer
The idea of Divide and Conquer is that if your enemy is more powerful than you, you should divide your enemy into parts that you can conquer easily. D
Backtracking
When they said ‘Two steps forward, one step back, they were talking about backtracking. In backtracking, we try out various outcomes possible for one
Sorting Based Problems
Sorting-based algorithms are the ones that help in rearranging the data according to a given criterion. The contacts in your phonebook are sorted lexicographically. The cash in your wallet might be sorted in ascending or descending order. The posts on your Instagram wall are actually sorted from latest to oldest. Let’s learn about some of the most popular sorting problems to make your life and programming easier.
Maximum Gap
By Arun Nawani
● Published At Nov 2021
Our task in this problem would be to find and return the maximum Difference between any two consecutive elements in a sorted array. ... Keep reading ..
Maximum Sum Path
By Vibhor Bhatnagar
● Published At Dec 2021
This article will discuss the problem of finding the maximum sum path from two arrays. ... Keep reading ..
Maximum Divisors in a Range
By Vibhor Bhatnagar
● Published At Dec 2021
This article will discuss the problem of finding the maximum divisors in a range. ... Keep reading ..
Find all indices of a given element in the sorted form of the given array
By Sandeep kamila
● Published At Dec 2021
This article covers finding all indices of a given element in the sorted form of the given array.... Keep reading ..
Sort all even numbers in the Array without changing the order of odd elements
By Sandeep kamila
● Published At Dec 2021
This article covers how to sort all even numbers in the array without changing the order of odd elements with examples and code in C++.... Keep reading ..
Bit manipulation
The act of algorithmically manipulating bits or other chunks of data shorter than a word is known as bit manipulation. It is used for error detection, correction algorithms, and solving various other problems in Data Structure and Algorithms. It is sometimes necessary to consider data at the bit level. The most crucial point is that operations can be completed in constant time using bit manipulation. Since bit manipulations are executed in parallel, they can sometimes eliminate or reduce the requirement to loop over a data structure, resulting in many-fold speedups. For bit manipulation, programming languages such as C, C++, and Java support six bitwise operators.
Hamming Distance
By Rhythm Jain
● Published At Oct 2021
This article discusses the problem of Hamming Distance, where we have to calculate the hamming distance between two integers.... Keep reading ..
Total Hamming Distance
By Soumya Agrawal
● Published At Oct 2021
This article will brief you about the hamming distance between two integers is the number of positions where the corresponding bits will be different. ... Keep reading ..
Ugly Numbers 2
● Published At Oct 2021
This article discusses the problem of Ugly Numbers 2, where we have to find the nth ugly number.... Keep reading ..
Longest Consecutive Sequence of 1’s in the Binary Representation of a Number
By Akshat Chaturvedi
● Published At Oct 2021
In this blog post, we’ll study one easy problem from the topic of data structures: finding the longest consecutive sequence of 1’s in the binary representation of a number. ... Keep reading ..
Bitwise AND of Numbers Range
By Ishita Chawla
● Published At Dec 2021
This blog will discuss the different ways to solve the problem of bitwise AND of Numbers Range, subsequently discussing the time and space complexity. ... Keep reading ..
Find Elements
By Husen Kagdi
● Published At Dec 2021
In this blog, we will discuss a famous interview coding question, “Find Elements” and its various solutions.... Keep reading ..
Minimum X (xor) A
By Malay Gain
● Published At Oct 2021
In this article, we will learn about the problem Minimum X (xor) A and solve how to find the value of X for which X xor A is the minimum, and X should satisfy the given condition. ... Keep reading ..
Lucky Alive Person in a Circle
By Soumya Agrawal
● Published At Oct 2021
This blog will help you build logic for the problem Luckiest Person and other problems related to this.... Keep reading ..
Gray Code
By Harsh Goyal
● Published At Oct 2021
This article will introduce Gray Code and give an introduction to Gray Code and will provide approaches to use it in different data structure problems.... Keep reading ..
Count Number of Set Bits in an Integer
By Ishita Chawla
● Published At Dec 2021
In this blog, we will be discussing four different approaches to count the total number of set bits in the binary representation of an integer. ... Keep reading ..
Number of Steps to Reduce a Number in Binary Representation to One
By vaishnavi pandey
● Published At Oct 2021
In this, we will discuss the problem i.e number of steps to reduce a number to one and its approach to code. ... Keep reading ..
Divide Two Integers
By Ishita Chawla
● Published At Dec 2021
This blog will discuss the problem of divide two integers and solve it using different approaches focusing on the time and space of each approach.... Keep reading ..
String
A string is a data type in programming languages. It consists of a sequence of characters. Strings are usually declared inside double quotes like- "hello." Each character in a string has a specific index, where the indexing starts from 0.
Basic String Problems
Due to the various string manipulation methods available in modern programming languages, we can find the length of a string, search for a specific ch
Advanced String Algorithms
Advanced string algorithms often use Dynamic programming to perform some operations on a string or multiple strings. Examples of such algorithms are R
Number Theory
Number Theory is concerned mainly with the study of properties of positive integers. Problems in competitive programming involving Maths are usually based on number theory. If we know number theory, it increases our ability to solve more challenging problems, clears our concepts, and helps us get a solid hold on programming.
Basics
Number theory involves various types of integers like prime numbers, composite numbers, and the relation between them. Base numbers and arithmetics nu
Advanced
The advanced topics that come under Number Theory are Modular Exponentiation, Fermat's Little Theorem, Wilson's Theorem, Chinese Remainder Theorem, Eu
Greedy
Greedy is one kind of algorithmic paradigm that follows the approach of making the locally optimal choice at each stage that leads to the globally optimum solution. A greedy algorithm always takes the best immediate or local solution while finding the final solution. Any problem having optimal substructure and greedy property can be solved using a greedy algorithm.
Basic Greedy Problems
To solve any basic greedy problem, identify an optimal subproblem or substructure in the problem and solve the subproblems in an optimal way. Create s
Optimization Problems
The optimization problem is the problem of finding the best solution from all feasible solutions. To solve these problems constraints must be known. T
Dynamic Programming
Dynamic Programming is a technique of doing an optimization over recursion. We store the answer for the overlapping subproblems and use that result if we need the answer for the same problem in the future. Hence, we save the time of re-computing the answer for the same problem. It is a great technique that helps us to reduce the exponential time complexity to polynomial time complexity.
Basics
Dynamic Programming is a technique to solve a complex problem by breaking it in terms of smaller sub-problems followed by solving each subproblem only
Advanced
One of the most frightening topics in DSA is dynamic programming. To tackle a dynamic problem, first, create the recursive approach, then look for rep
Range Query
In Range Query problems, we commonly are given an array of N integers and Q queries of one or more types. The range [L, R] of the query will also be given, and based on it, we will have to perform some function on the given array. Prefix Arrays, Segment Trees, Fenwick Trees, Mo's Algorithm are the various efficient methods to solve Range Query problems.
Segment Tree
The time complexity of range queries over an array, such as sum query over an interval or max number in an interval, is O(n). A segment tree is a data
Fenwick Tree
Fenwick Tree, also known as Binary Indexed Tree (BIT), provides an efficient way to compute prefix sum on an array allowing array modification. Consid
AVL Tree
The AVL Tree is a height-balanced binary search tree in which each node has a balance factor that is computed by subtracting the height of the right sub-tree from the height of the left sub-tree. If the balance factor of each node is between -1 and 1, the tree is said to be balanced; otherwise, the tree is imbalanced and must be balanced.
Convert Sorted Array to Balanced BST
By Deeksha Sharma
● Published At Jan 2022
In this blog, we will learn how to build a binary search tree from a sorted array. Since the sorted array contains elements in sorted order, it becomes pretty easy to construct Balanced BST from it. ... Keep reading ..
Find the closest greater value for every element in the array
By Ayush Tiwari
● Published At Dec 2021
This blog discussed finding the closest greater value for every element in the array. Read the blog to learn these methods in detail... Keep reading ..
Red-Black Tree
A red-black tree is a self-balancing binary search tree with one extra bit at each node, which is commonly read as the color (red or black). These colors are used to keep the tree balanced as insertions and deletions are made. The tree's balance isn't ideal, but it's good enough to cut down on searching time and keep it around O(log n), where n is the total number of components in the tree.
Introduction To Red-Black Trees
By Shubham Agarwal
● Published At Oct 2021
In this Blog, We will read about the Red-Black Tree, and we will compare it with the AVL tree, and we will Study how various operations work in the Red-Black tree-like searching. Then We will discuss the application of the Red-Black Tree. ... Keep reading ..
Insertion In Red-Black Trees
By Malay Gain
● Published At Oct 2021
In this article, we will learn how to insert a new node in a Red-Black Tree.... Keep reading ..
Set
Sets are a type of data structure that can store all the unique values in it. There are ordered and unordered sets. When we add an element into the set, it only adds the new element if it is not already present in the set. Every element of the set, once added, is immutable. However, we can add and remove elements from the set.
Fair Candy Swap
By Soumya Agrawal
● Published At Nov 2021
In this blog, we will discuss the problem of swapping candies and see the various implementations of this problem.... Keep reading ..
Graph
A graph is a type of non-linear data structure. A graph is defined as a group of vertices, and edges are used to connect these vertices. There are many different types of graphs, such as directed, undirected, weighted, unweighted, cyclic, acyclic, etc. There are many real-life applications of the graph. They are used in maps, social media, path optimization algorithms, etc.
Basic
A graph is an ADT, here ADT refers to the Abstract Data Type, and it can be used to represent non-linear relationships and complex relationships betwe
Advanced
The advanced topics under Graph Data Structure include traversable and Euclidean graphs, isomorphic and homogeneous graphs, fuzzy graphs, etc. Questio
Miscellaneous
Explore detailed explanations as well as the implementation of various topics in Competitive Programming. These topics are important in interview preparations. Try to implement them yourself before moving on to the solutions.
Trie
Trie has the following properties for a set of strings: 1. The root node always represents the null node. 2. Every node's child is arranged alphabet
Computational Geometry
Computational geometry is a branch of computer science devoted to the study of algorithms that can be stated in terms of geometry. Some purely geometr
Disjoint Set
In computer science, a disjoint-set data structure is also called a union-find data structure or merge–find set. It is a data structure that stores a
Game Theory
Game Theory is a topic in competitive programming that usually comes in contests with a mixture of other topics like greedy, dynamic programming, etc.
scroll-indicator
scroll-indicator
puzzle icon

Top Problems related to Competitive Programming