Articles on Trending Technologies

Technical articles with clear explanations and examples

Find relative complement of two sorted arrays in C++

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

Suppose we have two sorted arrays arr1 and arr2, there sizes are m and n respectively. We have to find relative complement of two arrays. It means that we need to find all those elements which are present in arr1, but not in arr2. So if the arrays are like A = [3, 6, 10, 12, 15], and B = [1, 3, 5, 10, 16], then result will be [6, 12, 15]To solve this, we can use the set_difference function. As the problem is basically set difference operation.Example#include #include #include using namespace std; int main() {    int first[] = ...

Read More

Returning Value from a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 5K+ Views

You can return a value from Perl subroutine as you do in any other programming language. If you are not returning a value from a subroutine then whatever calculation is last performed in a subroutine is automatically also the return value.You can return arrays and hashes from the subroutine like any scalar but returning more than one array or hash normally causes them to lose their separate identities. So we will use references ( explained in the next chapter ) to return an array or hash from a function.ExampleLet's try the following example, which takes a list of numbers and ...

Read More

Find sum of all nodes of the given perfect binary tree in C++

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

Suppose we have a positive integer L, which represents the number of levels in a perfect binary tree. The leaf nodes in this perfect binary tree are numbered starting from 1 to n. Where the n is number of leaf nodes. The parent node is the sum of children. Our task is to write a program to print the sum of all of the nodes of this perfect binary tree. So if the tree is like below −So total sum is 30.If we see closer, we need to find the sum of all of the nodes. As the leaf nodes ...

Read More

Private Variables in a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 700 Views

By default, all variables in Perl are global variables, which means they can be accessed from anywhere in the program. But you can create private variables called lexical variables at any time with the my operator.The my operator confines a variable to a particular region of code in which it can be used and accessed. Outside that region, this variable cannot be used or accessed. This region is called its scope. Lexical scope is usually a block of code with a set of braces around it, such as those defining the body of the subroutine or those marking the code ...

Read More

Find the area of largest circle inscribed in ellipse in C++

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

Suppose we have an ellipse, with major and minor axis length 2a & 2b. We have to find the area of the largest circle that can be inscribed in it. So if the a = 5 and b = 3, then area will be 28.2734From the we can see that the radius of the maximum area circle inscribed in an ellipse will be the minor axis ‘b’. So the area will be A = π*b*bExample#include using namespace std; double inscribedCircleArea(double b) {    double area = 3.1415 * b * b;    return area; } int main() {    double a = 10, b = 8;    cout

Read More

Temporary Values via local() in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 364 Views

The local is mostly used when the current value of a variable must be visible to called subroutines in Perl. A Perl local just gives temporary values to global (meaning package) variables. This is known as dynamic scoping. Lexical scoping is done with my, which works more like C's auto declarationsIf more than one variable or expression is given to local, they must be placed in parentheses. This operator works by saving the current values of those variables in its argument list on a hidden stack and restoring them upon exiting the block, subroutine, or eval.ExampleLet's check the following example ...

Read More

Find the count of maximum contiguous Even numbers in C++

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

Suppose we have an array A with n elements. We have to find the maximum number of the contiguous even numbers in the given array. So if the array is like A = [1, 2, 3, 4, 6, 8, 7], then the count will be 3.We can solve this easily. We need two count variables one is max_current, and another is max_till_now. If an even number is found, then increase max_current, then compare it with max_till_now. Every time an odd element is found reset max_count to 0.Example#include using namespace std; int maxEvenContiguous(int arr[], int n) {    int max_current = ...

Read More

State Variables via state() in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 1K+ Views

There is another type of lexical variable in Perl, which is similar to private variables but they maintain their state and they do not get reinitialized upon multiple calls of the subroutines. These variables are defined using the state operator and available starting from Perl 5.9.4.ExampleLet's check the following example to demonstrate the use of state variables −#!/usr/bin/perl use feature 'state'; sub PrintCount {    state $count = 0; # initial value    print "Value of counter is $count";    $count++; } for (1..5) {    PrintCount(); }OutputWhen the above program is executed, it produces the following result −Value of ...

Read More

Find the final radiations of each Radiated Stations in C++

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

Suppose there are N stations in the straight line. Each of them has same non-negative power of radiation power. Every station can increase the radiation power of its neighboring stations in the following way.Suppose the station i with radiation power R, will increase (i – 1)th station’s radiation power, by R-1, (i - 2)th station’s radiation power by R-2, and will increase (i + 1)th station’s radiation power, by R-1, (i + 2)th station’s radiation power by R-2. So on. So for example, if the array is like Arr = [1, 2, 3], then the output will be 3, 4, ...

Read More

Find the first circular tour that visits all petrol pumps in C++

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

Suppose there is a circle, and there are n petrol pumps on the circle. We have two sets of data like −The amount of petrol that every petrol pump hasDistance from one petrol pump to anotherCalculate the first point, from where a truck will be able to complete the circle. Assume for 1 liter petrol, the truck can go 1 unit of distance. Suppose there are four petrol pumps, and the amount of petrol, and distance from the next petrol pump is as like [(4, 6), (6, 5), (7, 3), (4, 5)], the first point from where truck can make ...

Read More
Showing 28631–28640 of 61,299 articles
Advertisements