Server Side Programming Articles

Page 1421 of 2109

Maximum sum of hour glass in matrix in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 589 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

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

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

Maximum Sum Path in Two Arrays in C++

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

Problem statementGiven two sorted arrays such the arrays may have some common elements. Find the sum of the maximum sum path to reach from beginning of any array to end of any of the two arrays. We can switch from one array to another array only at common elements. Note that the common elements do not have to be at same indexes.Expected time complexity is O(m+n) where m is the number of elements in arr1[] and n is the number of elements in arrs2[]ExampleIf given input is then output is 35 arr1[] = {2, 3, 7, 10, 12} ar2[] = ...

Read More

Spiral Matrix in C++

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

Suppose we have a matrix and we have to print the matrix elements in a spiral way. At first starting from the first row, print the whole content and then follow the last column to print, then the last row, and so on, thus it prints the elements in a spiral fashion. So if the matrix is like −123456789101112131415161718Then the output will be like [1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11 15 16]To solve this, we will follow these steps −currRow := 0 and currCol := 0while currRow and ...

Read More

Partition List in C++

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

Suppose we have a linked list and a value x. We have to make partitions. The partition it such that all nodes less than x comes before the nodes that are greater than or equal to x. We should preserve the original relative order of the nodes in each of these two partitions. So if the list is like [1, 4, 3, 2, 5, 2] and x = 3, then the output will be [1, 2, 2, 4, 3, 5]To solve this, we will follow these steps −Make dummy nodes d1 and d2, and initialize them with -1, create two ...

Read More

Binary Tree Level Order Traversal in C++

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

Suppose we have a binary tree. We have to traverse this tree using the level order traversal scheme. So if the tree is likeThe traversal sequence will be like − [10, 5, 16, 8, 15, 20, 23]To solve this, we will follow these steps −define queue que to store nodesinsert root into the que.while que is not empty, doitem := item present at front position of queueprint the value of itemif left of the item is not null, then insert left of item into queif right of the item is not null, then insert right of item into quedelete front ...

Read More

Evaluate Reverse Polish Notation in C++ Program

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

Suppose we have Reverse polish notation and we have to evaluate the value. The reverse polish notation is also known as postfix expression. Here we have to use the stack data structure to solve the postfix expressions.From the postfix expression, when some operands are found, pushed them in the stack. When some operator is found, two items are popped from stack and then the operation is performed in the correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack top. So ...

Read More

Python Program for Counting Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 273 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement− We are given an array, we need to sort the array using the concept of counting sort.Counting sort is a technique in which we work on keys between a specific range. It involves counting the number of objects which have distinct key & values. Finally, we do arithmetic calculations to obtain the position of each object and display the output.Now let’s observe the solution in the implementation below −Exampledef countSort(arr):    # The output character array that will have sorted arr    output = ...

Read More

Python Program for Cycle Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 351 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using the concept of cycle sort.It is an in-place algorithm and swapping takes place by the formation of cycles.Now let’s observe the solution in the implementation below −Exampledef cycleSort(array):    writes = 0    # cycles to be rotated    for cycleStart in range(0, len(array) - 1):       item = array[cycleStart]       #position to place the item       pos = cycleStart       for i in range(cycleStart ...

Read More
Showing 14201–14210 of 21,090 articles
Advertisements