Missing and Repeating in an Array
Last Updated :
23 Jul, 2025
Given an unsorted array arr[]
of size n
, containing elements from the range 1
to n
, it is known that one number in this range is missing, and another number occurs twice in the array, find both the duplicate number and the missing number.
Examples:
Input: arr[] = [3, 1, 3]
Output: [3, 2]
Explanation: 3 is occurs twice and 2 is missing.
Input: arr[] = [4, 3, 6, 2, 1, 1]
Output: [1, 5]
Explanation: 1 is occurs twice and 5 is missing.
[Approach 1] Using Visited Array - O(n) Time and O(n) Space
The idea is to use a frequency array to keep track of how many times each number appears in the original array. Since we know the numbers should range from 1 to n with each appearing exactly once, any number appearing twice is our repeating number, and any number with zero frequency is our missing number.
C++
#include <iostream>
#include <vector>
using namespace std;
vector<int> findTwoElement(vector<int>& arr) {
int n = arr.size();
// frequency array to count occurrences
vector<int> freq(n + 1, 0);
int repeating = -1, missing = -1;
// count frequency of each element
for (int i = 0; i < n; i++) {
freq[arr[i]]++;
}
// identify repeating and missing elements
for (int i = 1; i <= n; i++) {
if (freq[i] == 0) missing = i;
else if (freq[i] == 2) repeating = i;
}
return {repeating, missing};
}
int main() {
vector<int> arr = {3, 1, 3};
vector<int> ans = findTwoElement(arr);
cout << ans[0] << " " << ans[1] << endl;
return 0;
}
Java
import java.util.ArrayList;
class GfG {
static ArrayList<Integer> findTwoElement(int[] arr) {
int n = arr.length;
// frequency array to count occurrences
int[] freq = new int[n + 1];
int repeating = -1;
int missing = -1;
// count frequency of each element
for (int i = 0; i < n; i++) {
freq[arr[i]]++;
}
// identify missing and repeating numbers
for (int i = 1; i <= n; i++) {
if (freq[i] == 0) missing = i;
else if (freq[i] == 2) repeating = i;
}
ArrayList<Integer> result = new ArrayList<>();
result.add(repeating);
result.add(missing);
return result;
}
public static void main(String[] args) {
int[] arr = {3, 1, 3};
ArrayList<Integer> ans = findTwoElement(arr);
System.out.println(ans.get(0) + " " + ans.get(1));
}
}
Python
def findTwoElement(arr):
n = len(arr)
# frequency array to count occurrences
freq = [0] * (n + 1)
repeating = -1
missing = -1
# count frequency of each element
for num in arr:
freq[num] += 1
# identify missing and repeating numbers
for i in range(1, n + 1):
if freq[i] == 0:
missing = i
elif freq[i] == 2:
repeating = i
return [repeating, missing]
if __name__ == "__main__":
arr = [3, 1, 3]
ans = findTwoElement(arr)
print(ans[0], ans[1])
C#
using System;
using System.Collections.Generic;
class GfG {
static List<int> findTwoElement(int[] arr) {
int n = arr.Length;
// frequency array to count occurrences
int[] freq = new int[n + 1];
int repeating = -1, missing = -1;
// count frequency of each element
for (int i = 0; i < n; i++) {
freq[arr[i]]++;
}
// identify missing and repeating numbers
for (int i = 1; i <= n; i++) {
if (freq[i] == 0) missing = i;
else if (freq[i] == 2) repeating = i;
}
return new List<int> { repeating, missing };
}
static void Main() {
int[] arr = {3, 1, 3};
List<int> ans = findTwoElement(arr);
Console.WriteLine(ans[0] + " " + ans[1]);
}
}
Javascript
function findTwoElement(arr) {
let n = arr.length;
// frequency array to count occurrences
let freq = new Array(n + 1).fill(0);
let repeating = -1, missing = -1;
// count frequency of each element
for (let i = 0; i < n; i++) {
freq[arr[i]]++;
}
// identify missing and repeating numbers
for (let i = 1; i <= n; i++) {
if (freq[i] === 0) missing = i;
else if (freq[i] === 2) repeating = i;
}
return [repeating, missing];
}
// Driver Code
let arr = [3, 1, 3];
let ans = findTwoElement(arr);
console.log(ans[0], ans[1]);
[Approach 2] Using Array Marking - O(n) Time and O(1) Space
The main idea is to use the input array itself for tracking: it negates the value at the index corresponding to each element to mark it as visited. If it encounters a value that has already been negated, it identifies that number as the repeating one. In a second pass, it finds the index that remains positive, which corresponds to the missing number.
C++
#include <iostream>
#include <vector>
using namespace std;
vector<int> findTwoElement(vector<int>& arr) {
int n = arr.size();
int repeating = -1;
// mark visited indices by negating the value at
// that index
for (int i = 0; i < n; i++) {
int val = abs(arr[i]);
if (arr[val - 1] > 0) {
arr[val - 1] = -arr[val - 1];
} else {
// found the repeating element
repeating = val;
}
}
int missing = -1;
// the index with a positive value is the
// missing number
for (int i = 0; i < n; i++) {
if (arr[i] > 0) {
missing = i + 1;
break;
}
}
return {repeating, missing};
}
int main() {
vector<int> arr = {3, 1, 3};
vector<int> ans = findTwoElement(arr);
cout << ans[0] << " " << ans[1] << endl;
return 0;
}
Java
import java.util.ArrayList;
class GfG {
static ArrayList<Integer> findTwoElement(int[] arr) {
int n = arr.length;
int repeating = -1;
// traverse the array and mark visited indices
// by negating the value at index arr[i] - 1
for (int i = 0; i < n; i++) {
int val = Math.abs(arr[i]);
// if the value at index val - 1 is already negative
// it means we've seen this value before
if (arr[val - 1] > 0) {
arr[val - 1] = -arr[val - 1];
} else {
// if it's already negative, this value is
// the repeating one
repeating = val;
}
}
int missing = -1;
// after marking, the index with a positive value
// corresponds to the missing number
for (int i = 0; i < n; i++) {
if (arr[i] > 0) {
missing = i + 1;
break;
}
}
// return result: first repeating, then missing
ArrayList<Integer> result = new ArrayList<>();
result.add(repeating);
result.add(missing);
return result;
}
public static void main(String[] args) {
int[] arr = {3, 1, 3};
ArrayList<Integer> ans = findTwoElement(arr);
System.out.println(ans.get(0) + " " + ans.get(1));
}
}
Python
def findTwoElement(arr):
n = len(arr)
repeating = -1
# mark visited indices by negating the value
# at that index
for i in range(n):
val = abs(arr[i])
# if value at index val - 1 is already negative,
# val is repeating
if arr[val - 1] > 0:
arr[val - 1] = -arr[val - 1]
else:
# Already visited → repeating element
repeating = val
missing = -1
# the index with a positive value corresponds
# to the missing number
for i in range(n):
if arr[i] > 0:
missing = i + 1
break
return [repeating, missing]
if __name__ == "__main__":
arr = [3, 1, 3]
ans = findTwoElement(arr)
print(ans[0], ans[1])
C#
using System;
using System.Collections.Generic;
class GfG {
static List<int> findTwoElement(int[] arr) {
int n = arr.Length;
int repeating = -1;
// Mark visited indices by negating the
// value at that index
for (int i = 0; i < n; i++) {
int val = Math.Abs(arr[i]);
// If already negative, this value is repeating
if (arr[val - 1] > 0) {
arr[val - 1] = -arr[val - 1];
}
else {
// Repeated element found
repeating = val;
}
}
int missing = -1;
// the index with a positive value corresponds
// to the missing number
for (int i = 0; i < n; i++) {
if (arr[i] > 0) {
missing = i + 1;
break;
}
}
return new List<int> { repeating, missing };
}
static void Main() {
int[] arr = {3, 1, 3};
List<int> ans = findTwoElement(arr);
Console.WriteLine(ans[0] + " " + ans[1]);
}
}
Javascript
function findTwoElement(arr) {
let n = arr.length;
let repeating = -1;
// Mark visited indices by negating the value
// at the target index
for (let i = 0; i < n; i++) {
let val = Math.abs(arr[i]);
// If already negative, the number is repeating
if (arr[val - 1] > 0) {
arr[val - 1] = -arr[val - 1];
} else {
repeating = val;
}
}
let missing = -1;
// The index with a positive value corresponds
// to the missing number
for (let i = 0; i < n; i++) {
if (arr[i] > 0) {
missing = i + 1;
break;
}
}
return [repeating, missing];
}
// Driver Code
let arr = [3, 1, 3];
let ans = findTwoElement(arr);
console.log(ans[0], ans[1]);
[Approach 3] Making Two Math Equations - O(n) Time and O(1) Space
The idea is to use mathematical equations based on the sum and sum of squares of numbers from 1 to n. The difference between expected and actual sums will give us one equation, and the difference between expected and actual sum of squares will give us another equation. Solving these equations yields our missing and repeating numbers.
Illustration:
Note: This method can cause arithmetic overflow as we calculate the sum of squares (or product) and sum of all array elements.
C++
#include <iostream>
#include <vector>
using namespace std;
vector<int> findTwoElement(vector<int>& arr) {
int n = arr.size();
// Sum of first n natural numbers
long long s = (n * (n + 1)) / 2;
// Sum of squares of first n natural numbers
int ssq = (n * (n + 1) * (2 * n + 1)) / 6;
// Subtract actual values from expected sums
for (int i = 0; i < n; i++) {
s -= arr[i];
ssq -= arr[i] * arr[i];
}
// Using the equations: missing - repeating = s
// missing^2 - repeating^2 = ssq
int missing = (s + ssq / s) / 2;
int repeating = missing - s;
return {repeating, missing};
}
int main() {
vector<int> arr = {3, 1, 3};
vector<int> ans = findTwoElement(arr);
cout << ans[0] << " " << ans[1] << endl;
return 0;
}
Java
import java.util.ArrayList;
class GfG {
static ArrayList<Integer> findTwoElement(int[] arr) {
int n = arr.length;
// Expected sum and sum of squares for numbers from 1 to n
int s = (n * (n + 1)) / 2;
int ssq = (n * (n + 1) * (2 * n + 1)) / 6;
int missing = 0, repeating = 0;
// Subtract actual values from expected sums
for (int i = 0; i < n; i++) {
s -= arr[i];
ssq -= arr[i] * arr[i];
}
// Let x = missing, y = repeating
// s = x - y
// ssq = x^2 - y^2 = (x - y)(x + y) = s * (x + y)
// => x + y = ssq / s
// => x = (s + ssq / s) / 2
// => y = x - s
missing = (s + ssq / s) / 2;
repeating = missing - s;
ArrayList<Integer> res = new ArrayList<>();
res.add(repeating);
res.add(missing);
return res;
}
public static void main(String[] args) {
int[] arr = {3, 1, 3};
ArrayList<Integer> ans = findTwoElement(arr);
System.out.println(ans.get(0) + " " + ans.get(1));
}
}
Python
def findTwoElement(arr):
n = len(arr)
# Expected sum and sum of squares for numbers from 1 to n
s = (n * (n + 1)) // 2
ssq = (n * (n + 1) * (2 * n + 1)) // 6
missing = 0
repeating = 0
# Subtract actual sum and sum of squares from expected values
for num in arr:
s -= num
ssq -= num * num
# Let s = x - y and ssq = x^2 - y^2 = (x - y)(x + y)
# => x = (s + ssq // s) // 2, y = x - s
missing = (s + ssq // s) // 2
repeating = missing - s
return [repeating, missing]
if __name__ == "__main__":
arr = [3, 1, 3]
ans = findTwoElement(arr)
print(ans[0], ans[1])
C#
using System;
using System.Collections.Generic;
class GfG {
static List<int> findTwoElement(int[] arr) {
int n = arr.Length;
// Expected sum and sum of squares from 1 to n
int s = (n * (n + 1)) / 2;
int ssq = (n * (n + 1) * (2 * n + 1)) / 6;
int missing = 0, repeating = 0;
// Subtract actual values from expected ones
for (int i = 0; i < n; i++) {
s -= arr[i];
ssq -= arr[i] * arr[i];
}
// Let s = x - y, ssq = x^2 - y^2 = (x - y)(x + y)
// => x = (s + ssq / s) / 2, y = x - s
missing = (s + ssq / s) / 2;
repeating = missing - s;
return new List<int> { repeating, missing };
}
static void Main() {
int[] arr = { 3, 1, 3 };
List<int> ans = findTwoElement(arr);
Console.WriteLine(ans[0] + " " + ans[1]);
}
}
Javascript
function findTwoElement(arr) {
let n = arr.length;
// Expected sum and sum of squares from 1 to n
let s = (n * (n + 1)) / 2;
let ssq = (n * (n + 1) * (2 * n + 1)) / 6;
let missing = 0, repeating = 0;
// Subtract actual values from the expected ones
for (let i = 0; i < n; i++) {
s -= arr[i];
ssq -= arr[i] * arr[i];
}
// Let s = x - y, ssq = x^2 - y^2 = (x - y)(x + y)
// Solve: x = (s + ssq / s) / 2, y = x - s
missing = (s + ssq / s) / 2;
repeating = missing - s;
return [repeating, missing];
}
// Driver Code
let arr = [3, 1, 3];
let ans = findTwoElement(arr);
console.log(ans[0], ans[1]);
An Alternate way to make two equations:
- Let x be the missing and y be the repeating element.
- Get the sum of all numbers using formula S = n(n+1)/2 - x + y
- Get product of all numbers using formula P = 1*2*3*...*n * y / x
- The above two steps give us two equations, we can solve the equations and get the values of x and y.
[Approach 4] Using XOR - O(n) Time and O(1) Space
The idea is to use XOR operations to isolate the missing and repeating numbers. By XORing all array elements with numbers 1 to n, we get the XOR of our missing and repeating numbers. Then, using a set bit in this XOR result, we can divide all numbers into two groups, which helps us separate the missing and repeating numbers.
Refer to Find the two numbers with odd occurrences in an unsorted array to understand how groups will be created.
Step by step approach:
- XOR all array elements and numbers from 1 to n to get XOR of missing and repeating numbers.
- Find the rightmost set bit in this XOR result using
xorVal & ~(xorVal-1).
- Use this set bit to divide array elements and numbers 1 to n into two groups.
- XOR elements of first group to get x and second group to get y.
- Count occurrences of x in original array to determine which is missing and which is repeating.
- If x appears in array, x is repeating and y is missing; otherwise vice versa.
- Return both the repeating and missing numbers.
C++
#include <iostream>
#include <vector>
using namespace std;
vector<int> findTwoElement(vector<int>& arr) {
int n = arr.size();
int xorVal = 0;
// get the xor of all array elements
// and numbers from 1 to n
for (int i = 0; i < n; i++) {
xorVal ^= arr[i];
xorVal ^= (i + 1); // 1 to n numbers
}
// get the rightmost set bit in xorVal
int setBitIndex = xorVal & ~(xorVal - 1);
int x = 0, y = 0;
// now divide elements into two sets
// by comparing rightmost set bit
for (int i = 0; i < n; i++) {
// decide whether arr[i] is in first set
// or second
if (arr[i] & setBitIndex) {
x ^= arr[i];
}
else {
y ^= arr[i];
}
// decide whether (i+1) is in first set
// or second
if ((i+1) & setBitIndex) {
x ^= (i + 1);
}
else {
y ^= (i + 1);
}
}
// x and y are the repeating and missing values.
// to know which one is what, traverse the array
int missing, repeating;
int xCnt = 0;
for (int i=0; i<n; i++) {
if (arr[i] == x) {
xCnt++;
}
}
if (xCnt == 0) {
missing = x;
repeating = y;
}
else {
missing = y;
repeating = x;
}
return {repeating, missing};
}
int main() {
vector<int> arr = {3, 1, 3};
vector<int> ans = findTwoElement(arr);
cout << ans[0] << " " << ans[1] << endl;
return 0;
}
Java
import java.util.ArrayList;
class GfG {
static ArrayList<Integer> findTwoElement(int[] arr) {
int n = arr.length;
int xorVal = 0;
// get the xor of all array elements
// And numbers from 1 to n
for (int i = 0; i < n; i++) {
xorVal ^= arr[i];
xorVal ^= (i + 1); // 1 to n numbers
}
// get the rightmost set bit in xorVal
int setBitIndex = xorVal & ~(xorVal - 1);
int x = 0, y = 0;
// now divide elements into two sets
// by comparing rightmost set bit
for (int i = 0; i < n; i++) {
// decide whether arr[i] is in first set
// or second
if ((arr[i] & setBitIndex) != 0) {
x ^= arr[i];
}
else {
y ^= arr[i];
}
// decide whether (i+1) is in first set
// or second
if (((i + 1) & setBitIndex) != 0) {
x ^= (i + 1);
}
else {
y ^= (i + 1);
}
}
// x and y are the repeating and missing values.
// to know which one is what, traverse the array
int missing, repeating;
int xCnt = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == x) {
xCnt++;
}
}
if (xCnt == 0) {
missing = x;
repeating = y;
}
else {
missing = y;
repeating = x;
}
ArrayList<Integer> result = new ArrayList<>();
result.add(repeating);
result.add(missing);
return result;
}
public static void main(String[] args) {
int[] arr = {3, 1, 3};
ArrayList<Integer> ans = findTwoElement(arr);
System.out.println(ans.get(0) +" "+ ans.get(1));
}
}
Python
def findTwoElement(arr):
n = len(arr)
xorVal = 0
# get the xor of all array elements
# And numbers from 1 to n
for i in range(n):
xorVal ^= arr[i]
xorVal ^= (i + 1) # 1 to n numbers
# get the rightmost set bit in xorVal
setBitIndex = xorVal & ~(xorVal - 1)
x, y = 0, 0
# now divide elements into two sets
# by comparing rightmost set bit
for i in range(n):
# decide whether arr[i] is in first set
# or second
if arr[i] & setBitIndex:
x ^= arr[i]
else:
y ^= arr[i]
# decide whether (i+1) is in first set
# or second
if (i + 1) & setBitIndex:
x ^= (i + 1)
else:
y ^= (i + 1)
# x and y are the repeating and missing values.
# to know which one is what, traverse the array
xCnt = sum(1 for num in arr if num == x)
if xCnt == 0:
missing, repeating = x, y
else:
missing, repeating = y, x
return [repeating, missing]
if __name__ == "__main__":
arr = [3, 1, 3]
ans = findTwoElement(arr)
print(ans[0], ans[1])
C#
using System;
using System.Collections.Generic;
class GfG {
static List<int> findTwoElement(int[] arr) {
int n = arr.Length;
int xorVal = 0;
// get the xor of all array elements
// And numbers from 1 to n
for (int i = 0; i < n; i++) {
xorVal ^= arr[i];
xorVal ^= (i + 1); // 1 to n numbers
}
// get the rightmost set bit in xorVal
int setBitIndex = xorVal & ~(xorVal - 1);
int x = 0, y = 0;
// now divide elements into two sets
// by comparing rightmost set bit
for (int i = 0; i < n; i++) {
// decide whether arr[i] is in first set
// or second
if ((arr[i] & setBitIndex) != 0) {
x ^= arr[i];
}
else {
y ^= arr[i];
}
// decide whether (i+1) is in first set
// or second
if (((i + 1) & setBitIndex) != 0) {
x ^= (i + 1);
}
else {
y ^= (i + 1);
}
}
// x and y are the repeating and missing values.
// to know which one is what, traverse the array
int missing, repeating;
int xCnt = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == x) {
xCnt++;
}
}
if (xCnt == 0) {
missing = x;
repeating = y;
}
else {
missing = y;
repeating = x;
}
return new List<int> { repeating, missing };
}
static void Main() {
int[] arr = {3, 1, 3};
List<int> ans = findTwoElement(arr);
Console.WriteLine(ans[0] + " " + ans[1]);
}
}
Javascript
function findTwoElement(arr) {
let n = arr.length;
let xorVal = 0;
// Get the xor of all array elements
// And numbers from 1 to n
for (let i = 0; i < n; i++) {
xorVal ^= arr[i];
xorVal ^= (i + 1); // 1 to n numbers
}
// Get the rightmost set bit in xorVal
let setBitIndex = xorVal & ~(xorVal - 1);
let x = 0, y = 0;
// Now divide elements into two sets
// by comparing rightmost set bit
for (let i = 0; i < n; i++) {
// Decide whether arr[i] is in first set
// or second
if (arr[i] & setBitIndex) {
x ^= arr[i];
}
else {
y ^= arr[i];
}
// Decide whether (i+1) is in first set
// or second
if ((i + 1) & setBitIndex) {
x ^= (i + 1);
}
else {
y ^= (i + 1);
}
}
let xCnt = arr.filter(num => num === x).length;
let missing = xCnt === 0 ? x : y;
let repeating = xCnt === 0 ? y : x;
return [repeating, missing];
}
// Driver Code
let arr = [3, 1, 3];
let ans = findTwoElement(arr);
console.log(ans[0], ans[1]);
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