Server Side Programming Articles

Page 1400 of 2109

Find maximum height pyramid from the given array of objects in C++

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

Suppose we have an array of n objects. Each object has width W[i]. We have to arrange them in a pyramidal way like −Total width of ith is less than (i + 1)thTotal number of objects in the ith is less than (i + 1)thFor example, if the weights are like [40, 100, 20, 30], then output will be 2. So top level is 30, then lower level 20, 40 and 100To solve this, we will use the greedy approach. The idea is to use place the objects with lower width at the top, the next object at the level ...

Read More

Print calendar for a given year in C++

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

In this problem, we are given a year and we want to print the calendar for that year.The year calendar shows all days, months on every date of the month. And here we will create a program that will return the calendar of the current year.For this, we will need some calculations like, Number of days in a specific monthJanuary, March, May, July, August, October, December has 31 days.February has 28 days in a nonleap year and 29 days in a leap year.April, June, September, November has 30 days.Start Day (weekday) on the monthBased on the year and month, the ...

Read More

Find maximum sum possible equal sum of three stacks in C++

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

Suppose we have three stacks of positive numbers. We have to find the possible equal maximum sum of stacks with removal of top elements allowed. The stacks are represented as an array. The first index of the array represents the top element of the stack. Suppose the stack elements are like [3, 10], [4, 5] and [2, 1]. The output will be 0. The sum can only be equal after removing all elements from all stacks.To solve this, we will follow this idea. The idea is to compare the sum of each stack, if they are not equal, then remove ...

Read More

Print Binary Tree levels in sorted order in C++

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

In this problem, we are given a binary tree and we have to print all nodes at a level in sorted order of their values.Let’s take an example to understand the concept better, Input −Output −20 6 15 2 17 32 78To solve this problem, we need to print a sorted order of each level of the tree. For this, we need to create a queue and two priority queues. The NULL separator is used to separate two levels.ExampleProgram to illustrate the logic −#include #include #include using namespace std; struct Node {    int data;    struct Node ...

Read More

Find number of pairs (x, y) in an array such that x^y > y^x in C++

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

Suppose we have two arrays X and Y of positive integers. Find the number of pairs such that x^y > y^x, where x is an element of X and y is an element of Y. Suppose the X = [2, 1, 6], and Y = [1, 5], then output will be 3. As there are three pairs, these are (2, 1), (2, 5) and (6, 1)We can solve this in an efficient way. The logic is simple, it will be when y > x then x^y > y^x with some exceptions. So this is the trick.Sort the array Yfor each ...

Read More

Print Binary Tree in 2-Dimensions in C++

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

In this problem, we are given a binary tree and we have to print it two dimensional plane.Binary Tree is a special tree whose every node has at max two child nodes. So, every node is either a leaf node or has one or two child nodes.Example, Let’s take an example to understand the topic better −Output -      7    4 5       1    3       8Now as we have seen in the example, the nodes of the tree are printed in a 2-D output screen horizontally.Here, we have flipped the tree by ...

Read More

Find numbers of balancing positions in string in C++

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

Suppose we have a string. We have to find the balancing position count in that string from where left and right part of the string contains same characters. The frequency of characters does not matter. So if the string is “ABAABA”, then the number of balancing positions is 3. These positions are AB|AABA, ABA|ABA, ABAA|BA.To solve this, we will follow some efficient approach. After traversing the string we first feel right[] with counts of all characters. Then traverse the string from left to right. For every character we increment its count in left[] and decrement the count in right. For ...

Read More

Print array elements that are divisible by at-least one other in C++

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

In this problem, we are given an array of integers and we have to print only those numbers that are divisible by at least one other element of the array.Let’s take an example to understand the concept better, Input : 3 12 16 21 Output : 12 21Explanation − 3 is the smallest so it can be divisible by any other number are 12 which is divisible by 3, 16 not divisible by 3 and then 21 which is divisible by 3. So, we will neglect 3 and 16.One easy way is to check if all elements are divisible ...

Read More

How to Read and Print an Integer value in C++

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

Here we will see how to read integer from user and display in C++. To take input we will use the cin operator, and to display we will use cout operator. The syntax will be like −Input −int x; cin >> x;Output −int x = 110; cout x;    cout

Read More

Timer in C++ using system calls

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

Here we will see how to design timer in C++ using a system call. We will not use any graphics or animations. Here timer means the stopwatch, that is up-counting the time. The used system calls are −sleep(n) − This will help the program to sleep for n number of secondssystem() − This is used to execute the system command by passing command as an argument to this function.Example#include #include #include #include using namespace std; int hrs = 0; int mins = 0; int sec = 0; void showClk() {    system("cls");    cout

Read More
Showing 13991–14000 of 21,090 articles
Advertisements