Remove all occurrences of a word from a given string using Z-algorithm
Last Updated :
23 Jul, 2025
Given two strings str of length N and word of length M, the task is to remove all the occurrences of the string word from the string str.
Examples:
Input: str = "asmGeeksasmasmForasmGeeks", word = "asm"
Output: GeeksForGeeks
Explanation:
Removing "asm" from the string, str modifies str to GeeksForGeeks
Input: str = "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching", word = "km"
Output: Z-algorithmishelpfulinsearching
Explanation:
Removing "km" from the string, str modifies str to "Z-algorithmishelpfulinsearching".
Naive Approach: The simplest approach to solve this problem is to iterate over the characters of the string str. For every index, check if a substring can be found whose starting index is equal to the current index and the substring is equal to the string, word. If found to be true, then remove the substring. Finally, print the string.
Time Complexity: O(N2)
Auxiliary Space: O(1)
STL-based Approach: Remove all the occurrence of the string word from the string str using replace() method.
Time Complexity: O(N2)
Auxiliary Space: O(1)
Efficient Approach: The above approach can be optimized using Z-algorithm. Follow the steps below to solve the problem:
- Initialize a string, say res, to store the string by removing the words from the given string str.
- Initialize an array, say Z[], to store the Z-value of the string.
- Find all occurrences of the string word in the given string str using Z-algorithm.
- Finally, traverse the array Z[] and check if z[i + length(word) + 1] is equal to length(word) or not. If found to be true, then update i += length(word) - 1.
- Otherwise, append current character into the string res.
Below is the implementation of the above approach:
C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to fill the Z-array for str
void getZarr(string str, int Z[])
{
int n = str.length();
int k;
// L Stores start index of window
// which matches with prefix of str
int L = 0;
// R Stores end index of window
// which matches with prefix of str
int R = 0;
// Iterate over the characters of str
for (int i = 1; i < n; ++i) {
// If i is greater than R
if (i > R) {
// Update L and R
L = R = i;
// If substring match with prefix
while (R < n && str[R - L] == str[R]) {
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else {
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1) {
// Update Z[i]
Z[i] = Z[k];
}
else {
// Start from R and check manually
L = i;
while (R < n && str[R - L] == str[R]) {
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
string goodStr(string str, string word)
{
// Create concatenated string "P$T"
string concat = word + "$" + str;
int l = concat.length();
// Store Z array of concat
int Z[l];
getZarr(concat, Z);
// Stores string, str by removing all
// the occurrences of word from str
string res;
// Stores length of word
int pSize = word.size();
// Traverse the array, Z[]
for (int i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.length()) {
res += str[i];
}
}
return res;
}
// Driver Code
int main()
{
string str
= "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
string word = "km";
cout << goodStr(str, word);
return 0;
}
Java
// Java program for the above approach
import java.util.*;
class GFG
{
// Function to fill the Z-array for str
static void getZarr(String str, int Z[])
{
int n = str.length();
int k;
// L Stores start index of window
// which matches with prefix of str
int L = 0;
// R Stores end index of window
// which matches with prefix of str
int R = 0;
// Iterate over the characters of str
for (int i = 1; i < n; ++i)
{
// If i is greater than R
if (i > R)
{
// Update L and R
L = R = i;
// If subString match with prefix
while (R < n && str.charAt(R - L) ==
str.charAt(R))
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else
{
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1)
{
// Update Z[i]
Z[i] = Z[k];
}
else
{
// Start from R and check manually
L = i;
while (R < n && str.charAt(R - L) ==
str.charAt(R))
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
static String goodStr(String str, String word)
{
// Create concatenated String "P$T"
String concat = word + "$" + str;
int l = concat.length();
// Store Z array of concat
int []Z = new int[l];
getZarr(concat, Z);
// Stores String, str by removing all
// the occurrences of word from str
String res="";
// Stores length of word
int pSize = word.length();
// Traverse the array, Z[]
for (int i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.length()) {
res += str.charAt(i);
}
}
return res;
}
// Driver Code
public static void main(String[] args)
{
String str
= "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
String word = "km";
System.out.print(goodStr(str, word));
}
}
// This code is contributed by 29AjayKumar
Python3
# Python 3 program for the above approach
# Function to fill the Z-array for str
def getZarr(st, Z):
n = len(st)
k = 0
# L Stores start index of window
# which matches with prefix of str
L = 0
# R Stores end index of window
# which matches with prefix of str
R = 0
# Iterate over the characters of str
for i in range(1, n):
# If i is greater than R
if (i > R):
# Update L and R
L = R = i
# If substring match with prefix
while (R < n and st[R - L] == st[R]):
# Update R
R += 1
# Update Z[i]
Z[i] = R - L
# Update R
R -= 1
else:
# Update k
k = i - L
# if Z[k] is less than
# remaining interval
if (Z[k] < R - i + 1):
# Update Z[i]
Z[i] = Z[k]
else:
# Start from R and check manually
L = i
while (R < n and st[R - L] == st[R]):
# Update R
R += 1
# Update Z[i]
Z[i] = R - L
# Update R
R -= 1
# Function to remove all the occurrences
# of word from str
def goodStr(st, word):
# Create concatenated string "P$T"
concat = word + "$" + st
l = len(concat)
# Store Z array of concat
Z = [0]*l
getZarr(concat, Z)
# Stores string, str by removing all
# the occurrences of word from str
res = ""
# Stores length of word
pSize = len(word)
# Traverse the array, Z[]
for i in range(l):
# if Z[i + pSize + 1] equal to
# length of word
if (i + pSize < l - 1 and Z[i + pSize + 1] == pSize):
# Update i
i += pSize - 1
elif (i < len(st)):
res += st[i]
return res
# Driver Code
if __name__ == "__main__":
st = "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching"
word = "km"
print(goodStr(st, word))
# This code is contributed by chitranayal.
C#
// C# program for the above approach
using System;
using System.Collections.Generic;
public class GFG
{
// Function to fill the Z-array for str
static void getZarr(string str, int[] Z)
{
int n = str.Length;
int k;
// L Stores start index of window
// which matches with prefix of str
int L = 0;
// R Stores end index of window
// which matches with prefix of str
int R = 0;
// Iterate over the characters of str
for (int i = 1; i < n; ++i)
{
// If i is greater than R
if (i > R)
{
// Update L and R
L = R = i;
// If subString match with prefix
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else
{
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1)
{
// Update Z[i]
Z[i] = Z[k];
}
else
{
// Start from R and check manually
L = i;
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
static string goodStr(string str, string word)
{
// Create concatenated String "P$T"
string concat = word + "$" + str;
int l = concat.Length;
// Store Z array of concat
int []Z = new int[l];
getZarr(concat, Z);
// Stores String, str by removing all
// the occurrences of word from str
string res="";
// Stores length of word
int pSize = word.Length;
// Traverse the array, Z[]
for (int i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.Length) {
res += str[i];
}
}
return res;
}
// Driver Code
static public void Main()
{
string str
= "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
string word = "km";
Console.WriteLine(goodStr(str, word));
}
}
// This code is contributed by sanjoy_62.
JavaScript
<script>
//js program for the above approach
// Function to fill the Z-array for str
function getZarr(str,Z)
{
let n = str.length;
let k;
// L Stores start index of window
// which matches with prefix of str
let L = 0;
// R Stores end index of window
// which matches with prefix of str
let R = 0;
// Iterate over the characters of str
for (let i = 1; i < n; ++i)
{
// If i is greater than R
if (i > R)
{
// Update L and R
L = R = i;
// If subString match with prefix
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else
{
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1)
{
// Update Z[i]
Z[i] = Z[k];
}
else
{
// Start from R and check manually
L = i;
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
function goodStr(str,word)
{
// Create concatenated String "P$T"
let concat = word + "$" + str;
let l = concat.length;
// Store Z array of concat
let Z = new Array(l);
getZarr(concat, Z);
// Stores String, str by removing all
// the occurrences of word from str
let res="";
// Stores length of word
let pSize = word.length;
// Traverse the array, Z[]
for (let i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.length) {
res += str[i];
}
}
return res;
}
// Driver Code
let str = "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
let word = "km";
document.write(goodStr(str, word));
</script>
C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to fill the Z-array for str
void getZarr(string str, int Z[])
{
int n = str.length();
int k;
// L Stores start index of window
// which matches with prefix of str
int L = 0;
// R Stores end index of window
// which matches with prefix of str
int R = 0;
// Iterate over the characters of str
for (int i = 1; i < n; ++i) {
// If i is greater than R
if (i > R) {
// Update L and R
L = R = i;
// If substring match with prefix
while (R < n && str[R - L] == str[R]) {
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else {
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1) {
// Update Z[i]
Z[i] = Z[k];
}
else {
// Start from R and check manually
L = i;
while (R < n && str[R - L] == str[R]) {
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
string goodStr(string str, string word)
{
// Create concatenated string "P$T"
string concat = word + "$" + str;
int l = concat.length();
// Store Z array of concat
int Z[l];
getZarr(concat, Z);
// Stores string, str by removing all
// the occurrences of word from str
string res;
// Stores length of word
int pSize = word.size();
// Traverse the array, Z[]
for (int i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.length()) {
res += str[i];
}
}
return res;
}
// Driver Code
int main()
{
string str
= "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
string word = "km";
cout << goodStr(str, word);
return 0;
}
Java
// Java program for the above approach
import java.util.*;
class GFG
{
// Function to fill the Z-array for str
static void getZarr(String str, int Z[])
{
int n = str.length();
int k;
// L Stores start index of window
// which matches with prefix of str
int L = 0;
// R Stores end index of window
// which matches with prefix of str
int R = 0;
// Iterate over the characters of str
for (int i = 1; i < n; ++i)
{
// If i is greater than R
if (i > R)
{
// Update L and R
L = R = i;
// If subString match with prefix
while (R < n && str.charAt(R - L) ==
str.charAt(R))
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else
{
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1)
{
// Update Z[i]
Z[i] = Z[k];
}
else
{
// Start from R and check manually
L = i;
while (R < n && str.charAt(R - L) ==
str.charAt(R))
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
static String goodStr(String str, String word)
{
// Create concatenated String "P$T"
String concat = word + "$" + str;
int l = concat.length();
// Store Z array of concat
int []Z = new int[l];
getZarr(concat, Z);
// Stores String, str by removing all
// the occurrences of word from str
String res="";
// Stores length of word
int pSize = word.length();
// Traverse the array, Z[]
for (int i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.length()) {
res += str.charAt(i);
}
}
return res;
}
// Driver Code
public static void main(String[] args)
{
String str
= "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
String word = "km";
System.out.print(goodStr(str, word));
}
}
// This code is contributed by 29AjayKumar
Python3
# Python 3 program for the above approach
# Function to fill the Z-array for str
def getZarr(st, Z):
n = len(st)
k = 0
# L Stores start index of window
# which matches with prefix of str
L = 0
# R Stores end index of window
# which matches with prefix of str
R = 0
# Iterate over the characters of str
for i in range(1, n):
# If i is greater than R
if (i > R):
# Update L and R
L = R = i
# If substring match with prefix
while (R < n and st[R - L] == st[R]):
# Update R
R += 1
# Update Z[i]
Z[i] = R - L
# Update R
R -= 1
else:
# Update k
k = i - L
# if Z[k] is less than
# remaining interval
if (Z[k] < R - i + 1):
# Update Z[i]
Z[i] = Z[k]
else:
# Start from R and check manually
L = i
while (R < n and st[R - L] == st[R]):
# Update R
R += 1
# Update Z[i]
Z[i] = R - L
# Update R
R -= 1
# Function to remove all the occurrences
# of word from str
def goodStr(st, word):
# Create concatenated string "P$T"
concat = word + "$" + st
l = len(concat)
# Store Z array of concat
Z = [0]*l
getZarr(concat, Z)
# Stores string, str by removing all
# the occurrences of word from str
res = ""
# Stores length of word
pSize = len(word)
# Traverse the array, Z[]
for i in range(l):
# if Z[i + pSize + 1] equal to
# length of word
if (i + pSize < l - 1 and Z[i + pSize + 1] == pSize):
# Update i
i += pSize - 1
elif (i < len(st)):
res += st[i]
return res
# Driver Code
if __name__ == "__main__":
st = "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching"
word = "km"
print(goodStr(st, word))
# This code is contributed by chitranayal.
C#
// C# program for the above approach
using System;
using System.Collections.Generic;
public class GFG
{
// Function to fill the Z-array for str
static void getZarr(string str, int[] Z)
{
int n = str.Length;
int k;
// L Stores start index of window
// which matches with prefix of str
int L = 0;
// R Stores end index of window
// which matches with prefix of str
int R = 0;
// Iterate over the characters of str
for (int i = 1; i < n; ++i)
{
// If i is greater than R
if (i > R)
{
// Update L and R
L = R = i;
// If subString match with prefix
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else
{
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1)
{
// Update Z[i]
Z[i] = Z[k];
}
else
{
// Start from R and check manually
L = i;
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
static string goodStr(string str, string word)
{
// Create concatenated String "P$T"
string concat = word + "$" + str;
int l = concat.Length;
// Store Z array of concat
int []Z = new int[l];
getZarr(concat, Z);
// Stores String, str by removing all
// the occurrences of word from str
string res="";
// Stores length of word
int pSize = word.Length;
// Traverse the array, Z[]
for (int i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.Length) {
res += str[i];
}
}
return res;
}
// Driver Code
static public void Main()
{
string str
= "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
string word = "km";
Console.WriteLine(goodStr(str, word));
}
}
// This code is contributed by sanjoy_62.
JavaScript
<script>
//js program for the above approach
// Function to fill the Z-array for str
function getZarr(str,Z)
{
let n = str.length;
let k;
// L Stores start index of window
// which matches with prefix of str
let L = 0;
// R Stores end index of window
// which matches with prefix of str
let R = 0;
// Iterate over the characters of str
for (let i = 1; i < n; ++i)
{
// If i is greater than R
if (i > R)
{
// Update L and R
L = R = i;
// If subString match with prefix
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
else
{
// Update k
k = i - L;
// if Z[k] is less than
// remaining interval
if (Z[k] < R - i + 1)
{
// Update Z[i]
Z[i] = Z[k];
}
else
{
// Start from R and check manually
L = i;
while (R < n && str[R - L] ==
str[R])
{
// Update R
R++;
}
// Update Z[i]
Z[i] = R - L;
// Update R
R--;
}
}
}
}
// Function to remove all the occurrences
// of word from str
function goodStr(str,word)
{
// Create concatenated String "P$T"
let concat = word + "$" + str;
let l = concat.length;
// Store Z array of concat
let Z = new Array(l);
getZarr(concat, Z);
// Stores String, str by removing all
// the occurrences of word from str
let res="";
// Stores length of word
let pSize = word.length;
// Traverse the array, Z[]
for (let i = 0; i < l; ++i) {
// if Z[i + pSize + 1] equal to
// length of word
if (i + pSize < l - 1 && Z[i + pSize + 1] == pSize) {
// Update i
i += pSize - 1;
}
else if (i < str.length) {
res += str[i];
}
}
return res;
}
// Driver Code
let str = "Z-kmalgorithmkmiskmkmkmhelpfulkminkmsearching";
let word = "km";
document.write(goodStr(str, word));
</script>
Time Complexity: O(N + M)
Auxiliary Space: O(N)
Similar Reads
Basics & Prerequisites
Data Structures
Getting Started with Array Data StructureArray is a collection of items of the same variable type that are stored at contiguous memory locations. It is one of the most popular and simple data structures used in programming. Basic terminologies of ArrayArray Index: In an array, elements are identified by their indexes. Array index starts fr
14 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