Print indices of pair of array elements required to be removed to split array into 3 equal sum subarrays
Last Updated :
23 Jul, 2025
Given an array arr[] consisting of N integers, the task is to print the indices of two array elements required to be removed such that the given array can be split into three subarrays of equal sum. If not possible to do so, then print "-1".
Examples:
Input: arr[] = {2, 5, 12, 7, 19, 4, 3}
Output: 2 4
Explanation:
Removing arr[2] and arr[4] modifies arr[] to {2, 5, 7, 4, 3}.
Sum of subarray {arr[0], arr[1]} = 7.
arr[2] = 7.
Sum of subarray {arr[3], arr[4]} = 7.
Input: arr[] = {2, 1, 13, 5, 14}
Output: -1
Naive Approach: The simplest approach is to generate all possible pairs of array elements and for each pair, check if removal of these pairs can generate three equal sum subarrays from the given array.
Below is the implementation of the above approach:
C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to check if array can
// be split into three equal sum
// subarrays by removing two elements
void findSplit(int arr[], int N)
{
for (int l = 1; l <= N - 4; l++) {
for (int r = l + 2; r <= N - 2; r++) {
// Stores sum of all three subarrays
int lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
for (int i = 0; i <= l - 1; i++) {
lsum += arr[i];
}
// Sum of middle subarray
for (int i = l + 1; i <= r - 1; i++) {
msum += arr[i];
}
// Sum of right subarray
for (int i = r + 1; i < N; i++) {
rsum += arr[i];
}
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
cout << l << " " << r << endl;
return;
}
}
}
// If no pair exists, print -1
cout << -1 << endl;
}
// Driver code
int main()
{
// Given array
int arr[] = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = sizeof(arr) / sizeof(arr[0]);
findSplit(arr, N);
return 0;
}
Java
// Java program for the above approach
import java.util.*;
class GFG
{
// Function to check if array can
// be split into three equal sum
// subarrays by removing two elements
static void findSplit(int arr[], int N)
{
for (int l = 1; l <= N - 4; l++)
{
for (int r = l + 2; r <= N - 2; r++)
{
// Stores sum of all three subarrays
int lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
for (int i = 0; i <= l - 1; i++) {
lsum += arr[i];
}
// Sum of middle subarray
for (int i = l + 1; i <= r - 1; i++) {
msum += arr[i];
}
// Sum of right subarray
for (int i = r + 1; i < N; i++) {
rsum += arr[i];
}
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
System.out.println( l + " " + r );
return;
}
}
}
// If no pair exists, print -1
System.out.print(-1 );
}
// Driver Code
public static void main(String[] args)
{
// Given array
int arr[] = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = arr.length;
findSplit(arr, N);
}
}
// This code is contributed by sanjoy_62.
Python3
# Python 3 program for the above approach
# Function to check if array can
# be split into three equal sum
# subarrays by removing two elements
def findSplit(arr, N):
for l in range(1, N - 3, 1):
for r in range(l + 2, N - 1, 1):
# Stores sum of all three subarrays
lsum = 0
rsum = 0
msum = 0
# Sum of left subarray
for i in range(0, l, 1):
lsum += arr[i]
# Sum of middle subarray
for i in range(l + 1, r, 1):
msum += arr[i]
# Sum of right subarray
for i in range(r + 1, N, 1):
rsum += arr[i]
# Check if sum of subarrays are equal
if (lsum == rsum and rsum == msum):
# Print the possible pair
print(l, r)
return
# If no pair exists, print -1
print(-1)
# Driver code
if __name__ == '__main__':
# Given array
arr = [2, 5, 12, 7, 19, 4, 3]
# Size of the array
N = len(arr)
findSplit(arr, N)
# This code is contributed by SURENDRA_GANGWAR.
C#
// C# program for the above approach
using System;
class GFG
{
// Function to check if array can
// be split into three equal sum
// subarrays by removing two elements
static void findSplit(int []arr, int N)
{
for (int l = 1; l <= N - 4; l++)
{
for (int r = l + 2; r <= N - 2; r++)
{
// Stores sum of all three subarrays
int lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
for (int i = 0; i <= l - 1; i++) {
lsum += arr[i];
}
// Sum of middle subarray
for (int i = l + 1; i <= r - 1; i++) {
msum += arr[i];
}
// Sum of right subarray
for (int i = r + 1; i < N; i++) {
rsum += arr[i];
}
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
Console.WriteLine( l + " " + r );
return;
}
}
}
// If no pair exists, print -1
Console.Write(-1 );
}
// Driver Code
public static void Main(string[] args)
{
// Given array
int []arr = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = arr.Length;
findSplit(arr, N);
}
}
// This code is contributed by AnkThon
JavaScript
<script>
// JavaScript program for the above approach
// Function to check if array can
// be split into three equal sum
// subarrays by removing two elements
function findSplit(arr, N)
{
for (let l = 1; l <= N - 4; l++)
{
for (let r = l + 2; r <= N - 2; r++)
{
// Stores sum of all three subarrays
let lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
for (let i = 0; i <= l - 1; i++) {
lsum += arr[i];
}
// Sum of middle subarray
for (let i = l + 1; i <= r - 1; i++) {
msum += arr[i];
}
// Sum of right subarray
for (let i = r + 1; i < N; i++) {
rsum += arr[i];
}
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
document.write( l + " " + r + "</br>");
return;
}
}
}
// If no pair exists, print -1
document.write(-1 );
}
// Given array
let arr = [ 2, 5, 12, 7, 19, 4, 3 ];
// Size of the array
let N = arr.length;
findSplit(arr, N);
</script>
Time Complexity: O(N3)
Auxiliary Space: O(1)
Efficient Approach: To optimize the above approach, the idea is to use Prefix Sum array technique to find all subarray sums in constant time. Follow the steps below to solve the problem:
- Initialize a vector sum of size N to store the prefix sum of the array.
- Initialize two variables, say l & r, to store the two indexes which are to be dropped in order to split the array into 3 equal sum subarrays.
- Sum of the three subarrays would be sum[l - 1], sum[r - 1] - sum[l] and sum[N - 1] - sum[r].
- Iterate over the range [1, N - 4] using a variable l:
- Iterate over the range [l + 2, N - 2] using variable r and check if at any point, left subarray sum is equal to middle subarray sum and right subarray sum, then print the values of l & r and return.
- If no such pair exists, print -1.
Below is the implementation of the above approach:
C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
void findSplit(int arr[], int N)
{
// Stores prefix sum array
vector<int> sum(N);
// Copy array elements
for (int i = 0; i < N; i++) {
sum[i] = arr[i];
}
// Traverse the array
for (int i = 1; i < N; i++) {
sum[i] += sum[i - 1];
}
for (int l = 1; l <= N - 4; l++) {
for (int r = l + 2; r <= N - 2; r++) {
// Stores sums of all three subarrays
int lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
cout << l << " " << r << endl;
return;
}
}
}
// If no such pair exists, print -1
cout << -1 << endl;
}
// Driver Code
int main()
{
// Given array
int arr[] = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = sizeof(arr) / sizeof(arr[0]);
findSplit(arr, N);
return 0;
}
Java
// Java program for the above approach
import java.util.*;
class GFG
{
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
static void findSplit(int arr[], int N)
{
// Stores prefix sum array
int []sum = new int[N];
// Copy array elements
for (int i = 0; i < N; i++)
{
sum[i] = arr[i];
}
// Traverse the array
for (int i = 1; i < N; i++)
{
sum[i] += sum[i - 1];
}
for (int l = 1; l <= N - 4; l++) {
for (int r = l + 2; r <= N - 2; r++) {
// Stores sums of all three subarrays
int lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
System.out.print(l+ " " + r +"\n");
return;
}
}
}
// If no such pair exists, print -1
System.out.print(-1 +"\n");
}
// Driver Code
public static void main(String[] args)
{
// Given array
int arr[] = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = arr.length;
findSplit(arr, N);
}
}
// This code is contributed by shikhasingrajput
Python3
# Python3 program for the above approach
# Function to check if array can
# be split into three equal sum
# subarrays by removing a pair
def findSplit(arr, N):
# Stores prefix sum array
sum = [i for i in arr]
# Traverse the array
for i in range(1, N):
sum[i] += sum[i - 1]
for l in range(1, N - 3):
for r in range(l + 2, N - 1):
# Stores sums of all three subarrays
lsum , rsum , msum =0, 0, 0
# Sum of left subarray
lsum = sum[l - 1]
# Sum of middle subarray
msum = sum[r - 1] - sum[l]
# Sum of right subarray
rsum = sum[N - 1] - sum[r]
# Check if sum of subarrays are equal
if (lsum == rsum and rsum == msum):
# Print possible pair
print(l, r)
return
# If no such pair exists, print -1
print (-1)
# Driver Code
if __name__ == '__main__':
# Given array
arr = [2, 5, 12, 7, 19, 4, 3 ]
# Size of the array
N = len(arr)
findSplit(arr, N)
# This code is contributed by mohit kumar 29.
C#
// C# program for the above approach
using System;
public class GFG
{
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
static void findSplit(int []arr, int N)
{
// Stores prefix sum array
int []sum = new int[N];
// Copy array elements
for (int i = 0; i < N; i++)
{
sum[i] = arr[i];
}
// Traverse the array
for (int i = 1; i < N; i++)
{
sum[i] += sum[i - 1];
}
for (int l = 1; l <= N - 4; l++) {
for (int r = l + 2; r <= N - 2; r++) {
// Stores sums of all three subarrays
int lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
Console.Write(l+ " " + r +"\n");
return;
}
}
}
// If no such pair exists, print -1
Console.Write(-1 +"\n");
}
// Driver Code
public static void Main(String[] args)
{
// Given array
int []arr = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = arr.Length;
findSplit(arr, N);
}
}
// This code is contributed by 29AjayKumar
JavaScript
<script>
// JavaScript program for the above approach
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
function findSplit(arr, N)
{
// Stores prefix sum array
let sum = new Array(N);
// Copy array elements
for (let i = 0; i < N; i++)
{
sum[i] = arr[i];
}
// Traverse the array
for (let i = 1; i < N; i++)
{
sum[i] += sum[i - 1];
}
for (let l = 1; l <= N - 4; l++) {
for (let r = l + 2; r <= N - 2; r++) {
// Stores sums of all three subarrays
let lsum = 0, rsum = 0, msum = 0;
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Check if sum of subarrays are equal
if (lsum == rsum && rsum == msum) {
// Print the possible pair
document.write(l+ " " + r +"</br>");
return;
}
}
}
// If no such pair exists, print -1
document.write(-1 +"</br>");
}
// Given array
let arr = [ 2, 5, 12, 7, 19, 4, 3 ];
// Size of the array
let N = arr.length;
findSplit(arr, N);
</script>
Time Complexity: O(N2)
Auxiliary Space: O(N)
Most Optimal Approach: The most optimal idea is to make use of the two-pointer technique along with the use of Prefix Sum. Follow the steps below to solve the problem:
- Initialize a vector of size N to store the prefix sum of the array.
- Initialize two variables, say l & r, to traverse the array using the two-pointer approach.
- Traverse the array till l < r or until either all three sums become equal:
- If the sum of the left subarray is greater than the sum of the right subarray, add an extra element to the right subarray. Therefore, reducing the value of r by 1.
- If the sum of the right subarray is greater than the sum of the left subarray, add an element to the left subarray. Therefore, increasing l by 1.
- If both the sum of left and right subarrays are equal, but not equal to the sum of the middle subarray increase l by 1 and reduce r by 1.
- If no such pair exists, print -1.
Below is the implementation of the above approach:
C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
void findSplit(int arr[], int N)
{
// Two pointers l and r
int l = 1, r = N - 2;
int lsum, msum, rsum;
// Stores prefix sum array
vector<int> sum(N);
sum[0] = arr[0];
// Traverse the array
for (int i = 1; i < N; i++) {
sum[i] = sum[i - 1] + arr[i];
}
// Two pointer approach
while (l < r) {
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Print split indices if sum is equal
if (lsum == msum and msum == rsum) {
cout << l << " " << r << endl;
return;
}
// Move left pointer if lsum < rsum
if (lsum < rsum)
l++;
// Move right pointer if rsum > lsum
else if (lsum > rsum)
r--;
// Move both pointers if lsum = rsum
// but they are not equal to msum
else {
l++;
r--;
}
}
// If no possible pair exists, print -1
cout << -1 << endl;
}
// Driver Code
int main()
{
// Given array
int arr[] = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = sizeof(arr) / sizeof(arr[0]);
findSplit(arr, N);
return 0;
}
Java
// Java program for the above approach
public class GFG
{
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
static void findSplit(int []arr, int N)
{
// Two pointers l and r
int l = 1, r = N - 2;
int lsum, msum, rsum;
// Stores prefix sum array
int sum[] = new int[N];
sum[0] = arr[0];
// Traverse the array
for (int i = 1; i < N; i++) {
sum[i] = sum[i - 1] + arr[i];
}
// Two pointer approach
while (l < r) {
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Print split indices if sum is equal
if (lsum == msum && msum == rsum) {
System.out.println(l + " " + r);
return;
}
// Move left pointer if lsum < rsum
if (lsum < rsum)
l++;
// Move right pointer if rsum > lsum
else if (lsum > rsum)
r--;
// Move both pointers if lsum = rsum
// but they are not equal to msum
else {
l++;
r--;
}
}
// If no possible pair exists, print -1
System.out.println(-1);
}
// Driver Code
public static void main (String[] args)
{
// Given array
int []arr = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = arr.length;
findSplit(arr, N);
}
}
// This code is contributed by AnkThon
Python3
# Python3 program for the above approach
# Function to check if array can
# be split into three equal sum
# subarrays by removing a pair
def findSplit(arr, N) :
# Two pointers l and r
l = 1; r = N - 2;
# Stores prefix sum array
sum = [0]*N;
sum[0] = arr[0];
# Traverse the array
for i in range(1, N) :
sum[i] = sum[i - 1] + arr[i];
# Two pointer approach
while (l < r) :
# Sum of left subarray
lsum = sum[l - 1];
# Sum of middle subarray
msum = sum[r - 1] - sum[l];
# Sum of right subarray
rsum = sum[N - 1] - sum[r];
# Print split indices if sum is equal
if (lsum == msum and msum == rsum) :
print(l,r);
return;
# Move left pointer if lsum < rsum
if (lsum < rsum) :
l += 1;
# Move right pointer if rsum > lsum
elif (lsum > rsum) :
r -= 1;
# Move both pointers if lsum = rsum
# but they are not equal to msum
else :
l += 1;
r -= 1;
# If no possible pair exists, print -1
print(-1);
# Driver Code
if __name__ == "__main__" :
# Given array
arr = [ 2, 5, 12, 7, 19, 4, 3 ];
# Size of the array
N = len(arr);
findSplit(arr, N);
# This code is contributed by AnkThon
C#
// C# program for the above approach
using System;
class GFG {
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
static void findSplit(int[] arr, int N)
{
// Two pointers l and r
int l = 1, r = N - 2;
int lsum, msum, rsum;
// Stores prefix sum array
int[] sum = new int[N];
sum[0] = arr[0];
// Traverse the array
for (int i = 1; i < N; i++) {
sum[i] = sum[i - 1] + arr[i];
}
// Two pointer approach
while (l < r) {
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Print split indices if sum is equal
if (lsum == msum && msum == rsum) {
Console.Write(l + " " + r);
return;
}
// Move left pointer if lsum < rsum
if (lsum < rsum)
l++;
// Move right pointer if rsum > lsum
else if (lsum > rsum)
r--;
// Move both pointers if lsum = rsum
// but they are not equal to msum
else {
l++;
r--;
}
}
// If no possible pair exists, print -1
Console.Write(-1);
}
static void Main()
{
// Given array
int[] arr = { 2, 5, 12, 7, 19, 4, 3 };
// Size of the array
int N = arr.Length;
findSplit(arr, N);
}
}
// This code is contributed by rameshtravel07.
JavaScript
<script>
// JavaScript program for the above approach
// Function to check if array can
// be split into three equal sum
// subarrays by removing a pair
function findSplit(arr, N)
{
// Two pointers l and r
let l = 1, r = N - 2;
let lsum, msum, rsum;
// Stores prefix sum array
let sum = new Array(N);
sum[0] = arr[0];
// Traverse the array
for (let i = 1; i < N; i++) {
sum[i] = sum[i - 1] + arr[i];
}
// Two pointer approach
while (l < r) {
// Sum of left subarray
lsum = sum[l - 1];
// Sum of middle subarray
msum = sum[r - 1] - sum[l];
// Sum of right subarray
rsum = sum[N - 1] - sum[r];
// Print split indices if sum is equal
if (lsum == msum && msum == rsum) {
document.write(l + " " + r);
return;
}
// Move left pointer if lsum < rsum
if (lsum < rsum)
l++;
// Move right pointer if rsum > lsum
else if (lsum > rsum)
r--;
// Move both pointers if lsum = rsum
// but they are not equal to msum
else {
l++;
r--;
}
}
// If no possible pair exists, print -1
document.write(-1);
}
// Given array
let arr = [ 2, 5, 12, 7, 19, 4, 3 ];
// Size of the array
let N = arr.length;
findSplit(arr, N);
</script>
Time Complexity: O(N)
Auxiliary Space: O(N)
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem