Server Side Programming Articles

Page 1200 of 2109

Program to check whether a string is subsequence of other in C++

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

Suppose we have two strings S and T. We have to check whether S is subsequence of T or not.So, if the input is like S = "abc", T = "adbrcyxd", then the output will be TrueTo solve this, we will follow these steps −if s is same as t, then −return truen := size of s, m := size of tj := 0for initialize i := 0, when i < n, update (increase i by 1), do −if t[j] is same as s[i], then −(increase j by 1)if j is same as size of t, then −return truereturn falseLet ...

Read More

Program to find sum of the right leaves of a binary tree in C++

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

Suppose we have a binary tree we have to find the sum of all right leaves in a given binary tree.So, if the input is likethen the output will be 17, as there are two right leaves in the binary tree, with values 7 and 10 respectively.To solve this, we will follow these steps −Define a function dfs(), this will take node, add, if node is null, then −returnif left of node is null and right of node is null and add is non-zero, then −ret := ret + val of nodedfs(left of node, false)dfs(right of node, true)From the main ...

Read More

Program to find spreadsheet column title from the column number in C++

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

Suppose we have a positive integer value; we have to find its corresponding column title as appear in a spread sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.So, if the input is like 29, then the output will be AC.To solve this, we will follow these steps −while n is non-zero, do −n := n − 1res := res + n mod 26 + ASCII of 'A'n := n / 26reverse the array resreturn resLet us see the following implementation to get better understanding −Example#include using namespace std; class ...

Read More

Program to pruning a given binary tree in C++

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

Suppose we have a binary tree, where every node's value is either a 0 or a 1. We have to find the same tree where every subtree not containing a 1 has been deleted. So if the tree is like −To solve this, we will follow these steps −Define a recursive method solve(), this will take the node. the method will be like −If node is null, then return nullleft of node := solve(left of node)right of node := solve(right of node)if left of node is null and right of node is also null and node value is 0, then ...

Read More

Program to count number of valid triangle triplets in C++

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

Suppose we have an array of numbers, we have to find the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. So if the input is like [2, 2, 3, 4], then the result will be 3 as there are three triplets [2, 3, 4] using first 2, [2, 3, 4] using second 2, and [2, 2, 3].To solve this, we will follow these steps −ret := 0, n := size of nums, sort numsfor i in range n − 1 down to 0right := i − 1, ...

Read More

Count numbers having 0 as a digit in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

We are provided a number N. The goal is to find the numbers that have 0 as digit and are in the range [1, N].We will do this by traversing numbers from 10 to N ( no need to check from 1 to 9 ) and for each number we will check each digit using a while loop. If any digit is found as zero increment count and move to next number otherwise reduce the number by 10 to check digits until number is >0.Let’s understand with examples.Input N=11Output Numbers from 1 to N with 0 as digit: 1Explanation Starting from i=10 to ...

Read More

Count numbers in range 1 to N which are divisible by X but not by Y in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 698 Views

We are provided a number N. The goal is to find the numbers that are divisible by X and not by Y and are in the range [1, N].Let’s understand with examples.Input N=20 X=5 Y=20Output Numbers from 1 to N divisible by X not Y: 2Explanation Only 5 and 15 are divisible by 5 and not 10.Input N=20 X=4 Y=7Output Numbers from 1 to N divisible by X not Y: 5Explanation Numbers 4, 8, 12, 16 and 20 are divisible by 4 and not 7.Approach used in the below program is as followsWe take an integer N.Function divisibleXY(int x, int y, int n) returns a count ...

Read More

Count of common multiples of two numbers in a range in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

We are given two numbers A and B. Also provided two numbers START and END to define a range of numbers. The Ath tile has paint white and Bth tile has paint black. If the tile is painted both black and white then it turns grey. The goal is to find the total number of grey tiles .We will do this by traversing numbers from START to END and for each number we will check if the number is multiple of both A and B. If yes increment count.Let’s understand with examples.Input START=10 END=20 A=3 B=6Output Common multiples of A and B ...

Read More

Count ordered pairs of positive numbers such that their sum is S and XOR is K in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 354 Views

We are given two numbers S and K. The goal is to find ordered pairs of positive numbers such that their sum is S and XOR is K.We will do this by starting from i=1 to i

Read More

Count ordered pairs with product less than N in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 234 Views

We are given a number N. The goal is to find ordered pairs of positive numbers such that their product is less than N.We will do this by starting from i=1 to i

Read More
Showing 11991–12000 of 21,090 articles
Advertisements