Articles on Trending Technologies

Technical articles with clear explanations and examples

Maximum sub-matrix area having count of 1's one more than count of 0's in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 191 Views

In this tutorial, we will be discussing a program to find maximum sub-matrix area having count of 1’s one more than count of 0’s.For this we will be provided with a matrix containing 0’s and 1’s. Our task is to get the sub-matrix of maximum area containing more 1’s than 0’sExample#include using namespace std; #define SIZE 10 //finding length of longest sub-matrix int lenOfLongSubarr(int arr[], int n, int& start, int& finish) {    unordered_map um;    int sum = 0, maxLen = 0;    for (int i = 0; i < n; i++) {       sum += ...

Read More

Find number of edges that can be broken in a tree such that Bitwise OR of resulting two trees are equal in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 379 Views

ConceptWith respect of a given tree with m nodes and a number associated with every node, we canbreak any tree edge which will result in the formation of 2 new trees. Here, we have to count the number of edges in this way so that the Bitwise OR of the nodes present in the two trees constructed after breaking that edge are equal. It should be noted that the value ofevery node is ≤ 10^6.Inputvalues[]={1, 3, 1, 3}      1    / | \   2 3 4Output2Here, the edge between 1 and 2 can be broken, the Bitwise ...

Read More

BK Tree Introduction in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 469 Views

BK tree or Burkhard tree is a form of a data structure usually used to perform spell checks based on Levenshtein distance. It is also used for string matching Autocorrect feature can be used making this data structure. Let's say we have some words in a dictionary and we need to check some other words for spelling errors. We need to have a collection of words that is close to the given word whose spelling is to be checked. For example, if we have the word “uck” The correct word can be (truck, duck, duck, suck). Therefore spelling mistakes can ...

Read More

Maximum subsequence sum such that no three are consecutive

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 423 Views

In this tutorial, we will be discussing a program to find maximum subsequence sum such that no three are consecutive.For this we will be provided with a series of positive integers. Our task is to find the maximum sum without taking in their consecutive positive integers in the sum value.Example#include using namespace std; //returning maximum subsequence without involving //three consecutive numbers int maxSumWO3Consec(int arr[], int n) {    int sum[n]; if (n >= 1) sum[0] = arr[0];    if (n >= 2) sum[1] = arr[0] + arr[1];    if (n > 2) sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] ...

Read More

Find original numbers from gcd() every pair in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 468 Views

ConceptWith respect of a given array array[] containing GCD of every possible pair of elements of another array, our task is to determine the original numbers which are used to compute the GCD array.Inputarray[] = {6, 1, 1, 13}Output13 6 gcd(13, 13) = 13 gcd(13, 6) = 1 gcd(6, 13) = 1 gcd(6, 6) = 6Inputarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 8, 11, 13, 3, 3}Output13 11 8 6 6MethodAt first, sort the array in decreasing order.Largest element will always be one of the ...

Read More

Block swap algorithm for array rotation in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

The block swap algorithm for array rotation is an efficient algorithm that is used for array rotation. It can do your work in O(n) time complexity.So, in array rotation, we are given an array arr[] of size n and a number k that define the no. of the element to be rotated.Let’s see an example on array rotations −Input  −arr[] = {4, 6, 1, 8, 9, 2}, k = 2 (number of rotations.)Output −{1, 8, 9, 2, 4, 6}Explanation − On rotation, we will shift the one element to the last position and shift the next elements to one position.Element ...

Read More

Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 265 Views

In this tutorial, we will be discussing a program to find maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST.For this we will be provided with a binary tree. Our task is to print the sum of a sub-tree which is also a binary search tree.Example#include using namespace std; //creating binary tree node struct Node {    struct Node* left; struct Node* right; int data;    Node(int data) {       this->data = data;       this->left = NULL;       this->right = NULL;    } }; struct Info { ...

Read More

Optimal Account Balancing in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 604 Views

Suppose a group of friends went on holiday and sometimes they lent each other money. So as an example, Amit paid for Bikram's lunch for $10. Then later Chandan gave Amit $5 for a taxi fare. We have to design a model where each transaction is taken as a tuple (x, y, z) which means person x gave person y $z.Assuming Amit, Bikram, and Chandan are person 0, 1, and 2 respectively the transactions can be represented as [[0, 1, 10], [2, 0, 5]]. If we have a list of transactions between a group of people, we have to find ...

Read More

Find pair for given sum in a sorted singly linked without extra space in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 236 Views

Suppose we have a singly linked list and a value x; we have to find a pair whose sum is same as x. We have to keep in mind that we cannot use any extra space and expected time complexity will be O(n).So, if the input is like 4→7→8→9→10→11→12, x = 19, then the output will be [(7, 12), (8, 11), (9, 10)]To solve this, we will follow these steps −Define a function convert_to_xor(), this will take start, prev := NULLwhile start is NULL, do −next_list_node := next of startnext of start := XOR of the address of next_list_node and ...

Read More

Sum of smaller elements of nodes in a linked list in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 193 Views

In this problem, we are given a linked list with a node consisting of two values and a pointer. Our task is to create a program to find the sum of smaller elements of a node in a linked list.Here, in the linked list we have two elements say X and Y. The program will find a minimum of x and y. The minimum elements from all nodes are added which is the required result.Input −(5, 2)->(7, 9)->(6, 3)->(36, 24)->(19, 26)->nullOutput −55Explanation −Let’s take the minimum of X and Y from each node −node1 - mini = 5 node2 - ...

Read More
Showing 27081–27090 of 61,297 articles
Advertisements