Server Side Programming Articles

Page 1350 of 2109

Templates and Static variables in C++

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

In this tutorial, we will be discussing a program to understand templates and static variables in C++.In case of function and class templates, each instance of the templates has its own local copy of the variables.Example#include using namespace std; template void fun(const T& x){    static int i = 10;    cout

Read More

Minimum Size Subarray Sum in C++

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

Suppose we have an array of n elements, and a positive integer s. We have to find the minimal length of a contiguous subarray, of which the sum is greater or equal to s. If there isn’t one, then return 0 instead. So if the array is like [2, 3, 1, 2, 3, 4] and sum is 7, then the output will be 2. This is the subarray [4, 3] has the minimum length for this case.To solve this, we will follow these steps −ans := 0, n := size of array A, j := 0 and sum := 0for ...

Read More

Wiggle Sort II in C++

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

Suppose we have an unsorted array nums, we have to rearrange it such that nums[0] < nums[1] > nums[2] < nums[3]. So if the input is like [1, 5, 1, 1, 6, 4], then the output will be [1, 4, 1, 5, 1, 6].To solve this, we will follow these steps −make one array x, that has same elements as numssort x arrayi := size of x – 1, j := (size of x – 1) / 2 and n := size of nums arrayfor l in range 0 to n – 1, increase l by 2 in each stepnums[l] ...

Read More

Non-overlapping Intervals in C++

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

Suppose we have a collection of intervals; we have to find the minimum number of intervals we need to remove to make the rest of the intervals non-overlapping. So if the intervals are [[1, 2], [2, 3], [3, 4], [1, 3]], then the output will be 1, as we have to remove [1, 3] to make all others are non-overlapping.To solve this, we will follow these steps −n := size of arrayif n is 0, then return 0count := 1sort the array based on the end time of the intervalsend := end date of the first intervalfor i in range ...

Read More

Flatten Binary Tree to Linked List in C++

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

Suppose we have a binary tree; we have to flatten it into linked list in place. So if the tree is like −The output tree will be −To solve this, we will follow these steps −ser prev := nullDefine a recursive function solve(), that will take root as input.if root is null, then returnsolve(right of root)solve(left of root)right of root := prev, left of root := nullprev := rootLet us see the following implementation to get better understanding −Example#include using namespace std; class TreeNode{    public:    int val;    TreeNode *left, *right;    TreeNode(int data){       ...

Read More

Pancake Sorting in C++

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

Suppose we have an array A, we will perform the Pancake sort technique on A. Here the main constraint is that we can use only one operation called rev(arr, i). This will reverse the elements of arr from 0 to ith position. This idea is like the selection sort. We repeatedly place the max element at end reduce the size of the array. So if the input is like [54, 85, 52, 25, 98, 75, 25, 11, 68], then the result will be [11, 25, 25, 52, 54, 68, 75, 85, 98]To solve this, we will follow these steps −size ...

Read More

Reorder List in C++

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

Suppose we have a linked list like l1 -> l2 -> l3 -> l4 -> … -> l(n-1) -> ln. We have to rearrange this list into the form l1 -> ln -> l2 -> l(n - 1) -> … and so on. Here the constraint is that, we cannot modify the values in the list nodes, only the node itself may be changed. So for example, if the list is like [1, 2, 3, 4, 5], then the output will be [1, 5, 2, 4, 3]To solve this, we will follow these steps −Define a method called reverse to ...

Read More

Minimum Remove to Make Valid Parentheses in C++

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

Suppose we have a string s of '(' , ')' and lowercase English characters. We have to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parenthese string is valid and return any valid string. A parentheses string is valid when all of these criteria are fulfilled −It is the empty string, contains lowercase characters only, orIt can be written as the form of AB (A concatenated with B), where A and B are valid strings, orIt can be written as the form of (A), where A is a valid string.So ...

Read More

Fraction to Recurring Decimal in C++

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

Suppose we have two integers representing the numerator and denominator of a fraction, we have to find fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. So if the numerator is 2 and denominator is 3, then the output will be “0.(6)”To solve this, we will follow these steps −if numerator is 0, then return 0define one array ansif the numerator < 0 and denominator > 0 or numerator 0 and denominator < 0, then insert negative symbol ‘-’ into the ans arraydivisor := |numerator| and dividend := |denominator|, remainder := divisor mod ...

Read More

Containership in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we will be discussing a program to understand containership in C++.The parameter if a certain class contains another class is called as containership. The inside class is called contained class, while the class in which it is present is called container class.Example#include using namespace std; class first {    public:    first(){       cout

Read More
Showing 13491–13500 of 21,090 articles
Advertisements