Knapsack — The Master DP Pattern

Knapsack derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items. The problem often arises in resource allocation where the decision-makers have to choose from a set of non-divisible projects or tasks under a fixed budget or time constraint, respectively. … Read more

Dynamic Programming (DP): A Complete Guide

Dynamic Programming (DP) is an optimisation technique that solves complex problems by breaking them down into smaller, overlapping subproblems and storing their results to avoid redundant calculations. About DP Why do we even need dynamic programming? Before DP, let’s understand the problem DP is solving. While solving a problem, we often end up solving the … Read more

Mastering the Sliding Window Technique

Many brute-force solutions run in O(N²) or worse, which is unacceptable for large inputs. The Sliding Window technique is one of the most powerful ways to cut down unnecessary work and bring solutions down to O(N) or O(N log N). If you’ve ever solved problems around subarrays, substrings, or continuous segments, chances are you’ve already … Read more

Prefix Sum (Pre Sum) in Competitive Programming

Let’s go deep into Prefix Sum (Pre Sum) from a competitive programming perspective.This is one of the fundamental techniques you’ll repeatedly use in array, string, DP, and number theory problems. What is Prefix Sum? For an array arr[0..n-1], the prefix sum array pre[i] is defined as: That is, the cumulative sum up to index i. … Read more

The Two Pointer Technique: A Complete Guide

The two pointer technique is one of the most common and powerful patterns used in competitive programming, data structures, and algorithms. It helps solve problems that involve searching, sorting, or traversing arrays, strings, or linked lists in an efficient way. Core The Two Pointers pattern is a common algorithmic technique used primarily to simplify problems … Read more

Mastering Greedy Algorithms

Greedy algorithms are one of the most elegant problem-solving strategies in computer science. They are fast, intuitive, and often surprisingly effective—but only when applied to the right problems. This guide walks you through the recipe for designing greedy algorithms, the common proof techniques, and the classic patterns you must know. What Is a Greedy Algorithm? … Read more

Math Tricks in Competitive Programming

Competitive programming is not just about knowing programming syntax—it’s a blend of logic, speed, and mathematics. Mastering a few essential math tricks can drastically boost your problem-solving skills and efficiency. Let’s explore the most powerful and commonly used math techniques in competitive programming. Prime Numbers A prime number is a number greater than 1 that … Read more

GCD and LCM: Essential Tools for Competitive Programming

GCD and LCM are foundational concepts in number theory and are widely used in areas such as simplifying fractions, cryptography, and solving Diophantine equations. GCD (Greatest Common Divisor) GCD of 12 and 18 So, the GCD is 6 Euclidean Algorithm for GCD This is an efficient method to find GCD: Code Euclidean Algorithm, Why it … Read more