GO
prefix-sum Archives - GeeksforGeeks
Courses
Tutorials
Interview Prep
DSA
Practice Problems
C
C++
Java
Python
JavaScript
Data Science
Machine Learning
Courses
Linux
DevOps
Similar Topics
Web Technologies
32.1K+ articles
DSA
20.8K+ articles
Misc
7.7K+ articles
Mathematical
5.1K+ articles
Arrays
4.2K+ articles
Greedy
1.4K+ articles
Searching
1.0K+ articles
subarray
658+ articles
array-range-queries
376+ articles
subarray-sum
192+ articles
prefix-sum
349+ posts
Recent Articles
Partition Into 4 with Min Sum Diff
Last Updated: 15 October 2026
Given an array arr[], partition it into four non-empty contiguous subarrays P, Q, R, and S. Let the sums of these subarrays be W, X, Y, and Z, respectively. Find the minim...
read more
DSA
Binary Search
prefix-sum
Arrays
Powerful Integers
Last Updated: 05 July 2025
You are given a 2D integer array intervals[][] of length n and integer k, where each intervals[i] = [start, end] represents a closed interval (i.e., all integers from star...
read more
DSA
prefix-sum
DSA
ASCII Range Sum
Last Updated: 28 July 2025
Given a string s consisting of lowercase English letters, identify all characters whose first and last occurrences are at different positions.For each such character, comp...
read more
DSA
prefix-sum
strings
DSA
Top Problems on Prefix Sum Technique for Interviews
Last Updated: 23 July 2025
The Prefix Sum Technique is a powerful and widely used approach in coding interviews, especially for optimizing queries related to subarray sums and cumulative computation...
read more
DSA
prefix-sum
CSES Solutions - Forest Queries
Last Updated: 23 July 2025
Given an N X N grid representing the map of a forest. Each square is either empty or contains a tree. The upper-left square has coordinates (1,1), and the lower-right squa...
read more
Picked
DSA
prefix-sum
CSES Problems
CSES Solutions – Static Range Sum Queries
Last Updated: 23 July 2025
Given an array arr[] of N integers, your task is to process Q queries of the form: what is the sum of values in range [a,b]?ExamplesInput: arr[] = {1, 3, 4, 8, 6, 1, 4, 2}...
read more
DSA
array-range-queries
prefix-sum
CSES Problems
CSES Solutions - Subarray Sums II
Last Updated: 23 July 2025
Given an array arr[] of N integers, your task is to count the number of subarrays having sum X.Examples: Input: N = 5, X = 7, arr[] = {2, -1, 3, 5, -2}Output: 2Explanation...
read more
Picked
DSA
prefix-sum
CSES Problems
Find the sum of elements after X deletions and Y sign inversions
Last Updated: 23 July 2025
Two Players A and B are engaged in a game with an array of positive integers arr[] of size N. The game starts with Player A deleting at max X elements from the array arr[]...
read more
Sorting
DSA
Arrays
prefix-sum
Maximize number of indices with prefix sum equal to 0
Last Updated: 10 April 2024
Given an array arr[] of size N, you can perform the following operation on the array any number of times: If arr[i]=0, we can replace it with any integer. Your task is to ...
read more
Picked
DSA
prefix-sum
Algorithms-Dynamic Programming
Geeks Premier League 2023
Rearrange the given array to minimize the indices with prefix sum at least arr[i]
Last Updated: 23 July 2025
Given an array arr[] consisting of N positive integers, rearrange the array to minimize the number of indices i such that the prefix sum from index 1 to index i-1 is great...
read more
Geeks Premier League
DSA
Arrays
prefix-sum
Arrays
DSA-Blogs
Geeks Premier League 2023
Connect through Content 2023
Minimum number of operations required to make all the elements positive
Last Updated: 04 April 2024
Given an array A[] of length N. You can apply the below operation:Choose an index i such that (i+1) element exists. After that choose any number X (positive or negative). ...
read more
DSA
prefix-sum
LIS
Arrays
CPP-Competitive-Programming
DSA-Blogs
Geeks Premier League 2023
Queries to find number of indexes where characters repeated twice in row in substring L to R
Last Updated: 23 July 2025
Given string S of size N consisting of lower case characters and 2d array Q[][2] of size M representing several queries of type {L, R} representing a range. The task for ...
read more
Strings
Geeks Premier League
DSA
Arrays
prefix-sum
Geeks Premier League 2023
Queries to find Maximum index R with bitwise AND from index L at least K
Last Updated: 23 July 2025
Given array A[] of size N and array Q[][2] of size M representing queries of the type {L, K}. The task for this problem is to answer queries for each query to find the lar...
read more
Geeks Premier League
DSA
Arrays
Binary Search
prefix-sum
Geeks Premier League 2023
Minimize the Sum of Absolute Costs of an Array Optimally
Last Updated: 18 January 2024
Given an array arr[] of costs, your task is to minimize the sum of the absolute differences between consecutive costs by performing following operation at most once. Opera...
read more
DSA
prefix-sum
math
Data Structures-Array
suffix-sum
Bitwise OR Triplets in a Binary String
Last Updated: 23 July 2025
Given a binary string S of length N, where S[i] represents an integer value. the task is to count the number of ways to choose three different indices ( 0 = i j k N) su...
read more
Strings
Geeks Premier League
DSA
prefix-sum
Geeks Premier League 2023
1
2
3
4
...
24