Articles on Trending Technologies

Technical articles with clear explanations and examples

Euler's Four Square Identity in C++

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

In this problem, we are given two numbers and we need to find the product of the numbers using Euler's four square Identity. Euler’s Four Square Identity is the method to find the product of two numbers which can be represented using the sum of four squares of the number if the numbers can be represented as sum of four squares.The product a * b can be represented as the sum of four squares ifa = x12 + x22 + x32 + x42 b = y12 + y22 + y32 + y42 a * b = z12 + z22 + z32 + z42Let’s take an example ...

Read More

Count Pairs of Consecutive Zeros in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 393 Views

We have a sequence generator that starts with 1. At each step 0 becomes 10 and 1 becomes 01. So following changes will occur at consecutive steps −Step 1 − 01Step 2 − 1001Step 3 − 01101001 ……The goal is to find the number of pairs of consecutive 0’s for a given number of steps.If input step is 1 pair of 0’s - 0, input step is 2 pair of 0’s - 1, input step is 3 pair of 0’s 1Step 4 − 1001011001101001Step 5 − 01101001100101101001011001101001We can observe that sequence is increasing in powers of 2 and repeats itself ...

Read More

Eulerian Number in C++

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

In mathematics, the Eulerian number is a special type of combination number. It defines the number of permutations in which the next element is a specific number greater than the previous one.Denoted as,  A(n, m) is permutation from 1 to n in which two numbers vary by m.Problem Statement: In this problem, we are given two numbers m and n. And we need to find the number of permutations that are the Eulerian Number.Let’s take an example to understand the problem, Input:  n = 4, m = 2Output: 11Explanation: All permutations of number from 1 to 4 are −1 2 3 4       ...

Read More

Count pairs in an array that hold i*arr[i] > j*arr[j] in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 277 Views

We are given an array of numbers. The goal is to find the pair of elements of array such that they hold the conditionIf (i*arr[i] > j*arr[j]) then (arr[i], arr[j]) is a valid pair.If the array is [ 5, 4, 3, 2, 1 ] then pairs will be [3, 1] and [2, 1].Let us understand with examples.Input − arr[] = [ 1, 5, 4, 1, 2, 8, 3 ]Output − Count of pairs in an array that hold i*arr[i] > j*arr[j] are − 3Explanation − Pairs are (5, 1), (4, 1), (8, 3)Input − arr[] = [ -1, -2, 3, ...

Read More

Program to Find Out the Minimum Parsing Tree in C++

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

Suppose we have a list of unique and sorted numbers that represent breakpoints in a string. We want to create a tree out of these rules −There are nodes that have a value (a, b) where a and b are breakpoints. This means the node spans from indices [a, b] in the string.The root node spans over every breakpoint. (the whole string).The spans of a node's left and right child are ordered, contiguous, and contains the parent node's span.Leaf nodes' index of 'a' in breakpoints is 1 before the index of 'b' in breakpoints.The cost of a tree is determined ...

Read More

How to create a residual plot in R with better looking aesthetics?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 411 Views

The default residual plot can be created by using the model object name in base R but that is not very attractive. To create a residual plot with better looking aesthetics, we can use resid_panel function of ggResidpanel package. It is created in the same way as the residual plot in base R, also it results in all the relevant graph in one window.ExampleConsider the below data frame −> x y df dfOutputx y 1 0.48508894 0.217379409 2 0.75113573 -0.657179470 3 -0.13075185 -0.549613217 4 -0.26867557 1.156736294 5 0.40407850 0.640387394 6 -0.23816272 -0.807847198 7 -0.57278583 0.600249694 8 -0.78222676 -0.711133218 9 1.70161645 ...

Read More

Evaluate a boolean expression represented as string in C++

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

In this problem, we are given a string exp that represents a boolean expression. Our task is to evaluate the boolean expression represented as String.The valid characters in the expression are −0 or 1 denoting the boolean value& denoting AND operation| denoting OR operation^ denoting XOR operationWe need to solve this expression and return the result.Let's take an example to understand the problem, Input: str = 1&1|0^1^0&1Output: 0Explanation: 1&1|0^1^0&11 AND 1 OR 0 XOR 1 XOR 0 AND 11 OR 0 XOR 1 XOR 0 AND 11 XOR 1 XOR 0 AND 10 XOR 0 AND 10 AND 10Solution Approach:A simple solution is ...

Read More

Count pairs in an array such that LCM(arr[i], arr[j]) > min(arr[i],arr[j]) in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 364 Views

We are given an array of positive integers. The goal is to find the count of pairs of elements of arr[] such that condition LCM( arr[i], arr[j] ) > minimum of ( arr[i], arr[j] ). That is, the lowest common multiple of elements in a pair is greater than the minimum of both.Note − pair ( arr[i], arr[j] ) is the same as ( arr[j], arr[i] ). Don’t count it twice.Let us understand with examples.Input − arr[] = [ 1, 5, 4, 2 ]Output − Count of pairs in an array such that LCM(arr[i], arr[j]) > min(arr[i], arr[j]) are − ...

Read More

Evaluate an array expression with numbers, + and - in C++

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

In this problem, we are given an array arr[] consisting of n character values denoting an expression. Our task is to evaluate an array expression with numbers, + and –. The expression consists of only, numbers, ‘+’ character and ‘- ’ character.Let’s take an example to understand the problem, Input: arr = {“5”, “+”, “2”, “-8”, “+”, “9”, }Output: 8Explanation: The expression is 5 + 2 - 8 + 9 = 8Solution Approach:The solution to the problem is found by performing each operation and then returning the value. Each number needs to be converted to its equivalent integer value.Program to illustrate the working of ...

Read More

Count pairs in an array such that at least one element is prime in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 270 Views

We are given an array of positive integers. The goal is to find the count of distinct pairs of elements of an array that have at-least one prime member. If the array is [1, 2, 3, 4] then pairs would be (1, 2), (1, 3), (2, 3), (2, 4) and (3, 4).Let us understand with examplesInput − arr[] = { 1, 2, 4, 8, 10 };Output − Count of pairs in an array such that at least one element is prime are − 4Explanation − The only prime element is 2 and pairing it with all others will give − ...

Read More
Showing 25871–25880 of 61,297 articles
Advertisements