Articles on Trending Technologies

Technical articles with clear explanations and examples

Queries to update a given index and find gcd in range in C++

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

In this tutorial, we will be discussing a program to find queries to update a given index and find gcd in range.For this we will be provided with an array containing integers and Q queries. Our task is to find the result of given queries (updating a given value by X, finding the gcd between two given values).Example#include using namespace std; //getting middle index int findMiddle(int s, int e) {    return (s + (e - s) / 2); } //updating values at given indices void updateIndexValue(int* st, int ss, int se, int i, int diff, int si) { ...

Read More

User Defined Literals in C++

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

Here we will see the concept of the user-defined literals in C++. From C++ version 11, the User Defined Literals (UDL) are added in C++. C++ also provides literals for a variety of built-in types but these are limited.Built-in Literals −31 (Integer)3.5 (Double)4.2F (Float)'p' (Character)31ULL (Unsigned Long Long)0xD0 (Unsigned Hexadecimal Integer)"pq" (String)Apart from the built-in literals, sometimes we need user defined literals. There are few reasons behind that. Let us see with few examples −Suppose we want to define one weight variable, but we cannot specify the units, like if we define as follows −long double Weight = 3.5;We have ...

Read More

Acronym in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have a string s that is representing a phrase, we have to find its acronym. The acronyms should be capitalized and should not include the word "and".So, if the input is like "Indian Space Research Organisation", then the output will be ISROTo solve this, we will follow these steps −tokens:= each word of s as an arraystring:= blank stringfor each word in tokens, doif word is not "and", thenstring := string concatenate first letter of wordreturn convert string into uppercase stringLet us see the following implementation to get better understanding −Exampleclass Solution:    def solve(self, s):     ...

Read More

Querying the number of distinct colors in a subtree of a colored tree using BIT in C++

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

In this tutorial, we will be discussing a program to find querying the number of distinct colors in a subtree of a colored tree using BIT.For this we will be provided with rooted tree where each node has a color denoted by given array. Our task is to find all the distinct coloured nodes below the given node in the tree.Example#include #define MAXIMUM_COLOUR 1000005 #define MAXIMUM_NUMBER 100005 using namespace std; vector tree[MAXIMUM_NUMBER]; vector table[MAXIMUM_COLOUR]; int isTraversing[MAXIMUM_COLOUR]; int bit[MAXIMUM_NUMBER], getVisTime[MAXIMUM_NUMBER], getEndTime[MAXIMUM_NUMBER]; int getFlatTree[2 * MAXIMUM_NUMBER]; bool vis[MAXIMUM_NUMBER]; int tim = 0; vector< pair< pair, int> > queries; //storing results of each ...

Read More

Queries to return the absolute difference between Lth smallest number and the R-th smallest number in C++

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

In this tutorial, we will be discussing a program to find queries to return the absolute difference between L-th smallest number and the R-th smallest number.For this we will be provided with an array containing integers and Q queries. Our task is to find the absolute difference between the indices of Lth smallest and Rth smallest values.Example#include using namespace std; //returning the result of a query int respondingQuery(pair arr[], int l, int r) {    int result = abs(arr[l - 1].second - arr[r - 1].second);    return result; } //implementing the queries void calcDifference(int givenarr[], int a, int q[][2], ...

Read More

Construct a Binary Search Tree from given postorder in Python

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

Suppose we have the postorder traversal sequence of a binary search tree. We have to generate the tree from these sequences. So, if the postorder sequences is [9, 15, 7, 20, 3], then the tree will be −To form a tree we need inorder traversal also, but for binary search tree, the inorder traversal will be in the sorted form.Let us see the steps −Inorder = sorted list of postorder traversal.Define a method build_tree(), this will take inorder, postorder −If inorder list is not empty −root := make a tree node with the last value of postorder, then delete that ...

Read More

Construct a Binary Tree from Postorder and Inorder in Python

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

Suppose we have the inorder and postorder traversal sequence of a binary tree. We have to generate the tree from these sequences. So if the postorder and inorder sequences are [9, 15, 7, 20, 3] and [9, 3, 15, 20, 7], then the tree will be −Let us see the steps −Define a method build_tree(), this will take inorder, postorder −If inorder list is not empty −root := make a tree node with the last value of postorder, then delete that elementind := index of root data in inorder listright of root := build_tree(inorder from index ind to end, postorder)left ...

Read More

Query for ancestor-descendant relationship in a tree in C++

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

In this tutorial, we will be discussing a program to find query for ancestor-descendant relationship in a tree.For this we will be provided with a rooted tree and Q queries. Our task is to find the two roots given in the query is an ancestor of the other or not.Example#include using namespace std; //using DFS to find the relation between //given nodes void performingDFS(vector g[], int u, int parent, int timeIn[], int timeOut[], int& count) {    timeIn[u] = count++;    for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];   ...

Read More

Ancient Astronaut Theory in Python

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

Suppose er have a string dictionary, the dictionary is representing a partial lexicographic ordering of ancient astronauts' dictionary. So, if we have a string s, we have to check whether it's a lexicographically sorted string according to this ancient astronaut dictionary or not.So, if the input is like dictionary = "bdc", s = "bbbb h ddd i cccc", then the output will be TrueTo solve this, we will follow these steps −l := size of astro_dictif l is same as 0, thenreturn Truei := 0for each character c in s, doif c in astro_dict, thenwhile i < l and astro_dict[i] ...

Read More

Program to find correlation coefficient in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 2K+ Views

In this tutorial, we will be discussing a program to find correlation coefficient.For this we will be provided with two arrays. Our task is to find the correlation coefficient denoting the strength of the relation between the given values.Example#include using namespace std; //function returning correlation coefficient float find_coefficient(int X[], int Y[], int n){    int sum_X = 0, sum_Y = 0, sum_XY = 0;    int squareSum_X = 0, squareSum_Y = 0;    for (int i = 0; i < n; i++){       sum_X = sum_X + X[i];       sum_Y = sum_Y + Y[i];     ...

Read More
Showing 4201–4210 of 61,248 articles
« Prev 1 419 420 421 422 423 6125 Next »
Advertisements