Server Side Programming Articles

Page 1447 of 2109

Find maximum level product in Binary Tree in C++

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

Suppose, one binary tree is given. It has positive and negative nodes. We have to find the maximum product at each level of it.Consider this is the tree, so the product of level 0 is 4, product of level 1 is 2 * -5 = -10, and product of level 2 is -1 * 3 * -2 * 6 = 36. So this is the maximum one.To solve this, we will perform the level order traversal of the tree, during traversal, process doing the nodes of different levels separately. Then get the maximum product.Example#include #include using namespace std; class Node ...

Read More

Find maximum product of digits among numbers less than or equal to N in C++

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

Suppose, we have one integer N > 0. The task is to find the maximum product of digits among numbers less than or equal to N. If the N is 390, then the result is 216, as the number 389 is making maximum product 3 * 8 * 9 = 216.To solve this problem, we will use the recursive approach. So if N = 0, then return 1, if the number N < 10, then return N, otherwise return max(max_product(N/10) * (N mod 10), max_product((N/10) - 1)*9)Example#include using namespace std; int max_product(int N) {    if (N == 0)   ...

Read More

Program to print 'N' alphabet using the number pattern from 1 to n in C++

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

In this tutorial, we will be discussing a program to print ‘N’ alphabet using the number pattern from 1 to n.For this we will have to print the english alphabet N. Our task is to determine the size of the letter and print it back using the numbers from 1 to n.Example#include using namespace std; //printing the letter N void print_N(int N){    int index, side_index, size;    int Right = 1, Left = 1, Diagonal = 2;    for (index = 0; index < N; index++) {       cout

Read More

Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++

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

Suppose we have four integers a, b, c and k. We have to find the minimum positive value x, such that the following equation satisfies −𝑎𝑥2+𝑏𝑥+𝑐 ≥𝑘If a = 3, b = 4, c = 5 and k = 6, then output will be 1To solve this, we will use the bisection approach. The lower limit will be 0 since x has to be a minimum positive integer.Example#include using namespace std; int getMinX(int a, int b, int c, int k) {    int x = INT8_MAX;    if (k

Read More

Find maximum in stack in O(1) without using additional stack in C++

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

Suppose we want to make a stack that can store the maximum element in the stack. And we can get it in O(1) time. The constraint is that, it should not use any additional space, so O(1) extra space.We can make one user-defined stack, that will store the max value, when one operation is performed, like pop or peek, then the max will be returned. For peek operation, return the maximum of stack top and the max element, for pop operation, when the top element is larger, then print it and update max as 2*max – top_element. otherwise return top_element. ...

Read More

Find first non matching leaves in two binary trees in C++

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

Suppose we have two binary trees. We have to find first leaf of two trees, that does not match. If there are no non-matching leaves, then display nothing.If these are two trees, then the first non-matching leaves are 11 and 15.Here we will use the iterative preorder traversal of both of the trees simultaneously using stack. We will use different stack for different trees. We will push nodes into the stack till the top node is the leaf node. Compare two top, if they are same, then do further checking, otherwise show two stack top elements.Example#include #include using ...

Read More

Find the kth node in vertical order traversal of a Binary Tree in C++

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

Suppose we have a binary tree and a value K. The task is to print the Kth node in the vertical order traversal. If no such node exists, then return -1. So if the tree is like below −The vertical order traversal is like −4 2 1 5 6 3 8 7 9So if K = 3, then result will be 1.The approach is simple. We will perform the vertical order traversal, then check the current node is the kth node or not, if so then return.Example#include #include #include #include using namespace std; class Node {    public:    int ...

Read More

Program to print 2D shapes in C++

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

In this tutorial, we will be discussing a program to print out 2D shapes.For this we will be provided with the various parameters required to make a shape such as radius, side length and side breadth, etc. And our task is to print a shape accordingly with no thickness.Example#include using namespace std; void print_circle(int radius){    for (int i = 0; i

Read More

C++ program for Solving Cryptarithmetic Puzzles

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

In the crypt-arithmetic problem, some letters are used to assign digits to it. Like ten different letters are holding digit values from 0 to 9 to perform arithmetic operations correctly. There are two words are given and another word is given as answer of addition for those two words. As an example we can say that two words ‘BASE’ and ‘BALL’, and the result is ‘GAMES’. Now if we try to add BASE and BALL by their symbolic digits, we will get the answer GAMES.NOTE − There must be ten letters maximum, otherwise it cannot be solved.InputThis algorithm will take ...

Read More

Array Type Manipulation in C++

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

The array is a data structure in c++ that stored multiple data elements of the same data type in continuous memory locations.In c++ programming language, there are inbuilt functions to manipulate array types. Some functions can also be applied to multidimensional arrays. The array header file contains functions to manipulate arrays in c++ programming language.Some common methods to manipulate arrays in c++ are −is_array()This function is used to check if the variable passed to the function is of the type array or not. This method is strict in recognizing arrays that even std:: array is rejected in the check. The ...

Read More
Showing 14461–14470 of 21,090 articles
Advertisements