Programming Articles

Page 1435 of 2547

Maximum sum of hour glass in matrix in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 588 Views

In this problem, we are given a matrix. Our task is to create a program that finds the maximum sum of the hourglass in a matrix in C++.Program description − Here, we will find the maximum sum of all hourglasses that can be created for the given matrix elements.Hour glass is a 7 element shape made in the matrix in the following form, X X X   X X X XLet’s take an example to understand the problem, Input −array ={    {2 4 0 0}    {0 1 1 0}    {4 2 1 0}    {0 3 0 ...

Read More

Print all n-digit numbers with absolute difference between sum of even and odd digits is 1 in C++

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

In this problem, we are given an integer n, and we have to print all n-digit numbers such that the absolute difference between the sum of digit of the number at even and odd places is 1. While creating the numbers leading 0’s are not considered.The absolute difference is the difference between both numbers whose value is an absolute value (positive value).Let’s take an example to understand the problem −Input: n = 2 Output: 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 Explaination : taking an of the numbers from the ...

Read More

Maximum sum of i * arr[i] among all rotations of a given array in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 561 Views

In this problem, we are given an array arr. Our task is to create a program that will find the maximum sum of i*arr[i] among all rotations of the given array in C++.Program description − Here, we will find the maximum sum of out the sums of all the elements of the array multiplied by their index {i * arr[i]} in the rotation.Let’s take an example to understand the problem, Input − array arr = {4, 8, 1, 5}Output − 37Explanation −All rotations with the sum of i*arr[i] : {4, 8, 1, 5} = 4*0 + 8*1 + 1*2 + ...

Read More

Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue) in C++

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

In this tutorial, we will be discussing a program to convert a binary tree to a threaded binary tree using a queue data structure.For this, we will be provided with a binary tree. Our task is to convert that particular binary tree into a threaded binary tree by adding additional routes for quicker inorder traversal with the help of a queue data structure.Example#include #include using namespace std; //node structure for threaded tree struct Node {    int key;    Node *left, *right;    bool isThreaded; }; //putting the inorder pattern into a queue void convert_queue(Node* root, std::queue* q){ ...

Read More

Print all n-digit numbers whose sum of digits equals to given sum in C++

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

In this problem, we are given two numbers n and sum. We have to print all n digit numbers whose sum is equal to the sum. In this problem, numbers with leading 0’s are not considered.Let’s take an example to understand the problem, Input: n = 2 , sum = 5 Output: 14 23 32 41 50 Explanation: The sum of digits of the number in all numbers in 5.To solve this problem, we will have to find all the n-digit numbers with sum with the given sum value. For this, we will fix a digit place with all values ...

Read More

Maximum sum of lengths of non-overlapping subarrays with k as the max element in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 300 Views

In this problem, we are given an array and an integer k. Our task is to create a program that will find the maximum sum of lengths of non-overlapping subarrays with k as the max element in c++.Problem description − here, we have an array and an integer k. We have to find all possible non-overlapping sub-arrays that can be created from this array. And sum the lengths of all the subarrays created.Let’s take an example to understand the problem, Input − array = {3, 7, 1, 2, 3, 1, 6, 3, 2, 5} k = 3Output − 7Explanation − ...

Read More

Print all n digit patterns formed by mobile Keypad in C++

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

In this problem, we are given a number n and we have to print all N digit patterns formed by pressing the mobile keypad button. While pressing the buttons, we can press only nearby buttons of the current button i.e. only keys left, right, up, down can be pressed.Let’s see how the old keypad looks like −12ABC3DEF4GHI5JKL6MNO7PQRS8TUV9WXYZ*0#Let’s take an example to understand the problemInput: n=2 Output: 12 14 21 23 25 32 36 41 45 47 52 54 56 58 63 65 69 74 78 85 87 89 80 96 98To solve this problem, we will use a depth-first search ...

Read More

Maximum sum of non-leaf nodes among all levels of the given binary tree in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 274 Views

In this problem, we are given a binary tree. Our task is to create a program that will find the maximum sum of non-leaf nodes among all levels of the given binary tree in c++.Problem description − we will calculate the sum of all non-leaf nodes of the tree and every level and then print the maximum sum.Let’s take an example to understand the problem, Input −Output − 9Explanation − the sum of non-leaf nodes at each level −Level 1: 4 Level 2: 1+2 = 3 Level 3: 9 (4, 7 are leaf nodes) Level 4: 0To solve this problem, ...

Read More

Convert a BST to a Binary Tree such that sum of all greater keys is added to every key in C++

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

In this tutorial, we will be discussing a program to convert a BST to a binary tree such that the sum of all greater keys is added to every key.For this, we will be provided with a Binary Search tree. Our task is to convert that tree into a binary tree with the sum of all greater keys added to the current key. This will be done by the reverse in order of the given BST along with having the sum of all the previous elements and finally adding it to the current element.Example#include using namespace std; //node structure ...

Read More

Print all multiplicative primes <= N in C++

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

In this problem, we are given an integer n and we have to print all multiplicative primes less than or equal to n.Multiplicative primes are prime numbers that have a product of their digits also prime numbers. Like 2, 3, 5, 7, 13, 17.23 is prime but not a multiplicative prime because of 2*3 = 6.Let’s take an example to understand the problem −Input: n = 9 Output: 2 3 5 7To solve this problem, we will find all prime numbers less than n. And check if the number is multiplicative prime. And print all multiplicative prime less than n.ExampleThe ...

Read More
Showing 14341–14350 of 25,466 articles
Advertisements