Programming Articles - Page 1315 of 3366

Find pairs in array whose sums already exist in array in C++

sudhir sharma
Updated on 16-Mar-2021 04:57:22

335 Views

In this problem, we are given an array arr[] consisting of N integer. Our task is to find pairs in an array whose sums already exist in the array. We need to find pairs with sum value = a value in the arrayLet’s take an example to understand the problem, Inputarr[] = {1, 2, 4, 6, 7}Output(1, 6), (2, 4)ExplanationFor pairs (1, 6), the sum of values is 7 which is present in the array.For pairs (2, 4), the sum of values is 6 which is present in the array.Solution ApproachA simple solution to the problem is by finding all ... Read More

Find other two sides of a right angle triangle in C++

sudhir sharma
Updated on 16-Mar-2021 04:54:20

292 Views

In this problem, we are given an integer a denoting one side of a right angle triangle. We need to check whether it is possible to have a right angle triangle with side a. If it is possible, then find the other two sides of a right angle triangle.Let’s take an example to understand the problem, Inputa = 5OutputSides : 5, 12, 13ExplanationThe sides of right angle are found as 52 + 122 = 132Solution ApproachA simple solution to the problem is using pythagoras theorem. We know that the sides of a right angled triangle follow pythagoras theorem, which isa2 ... Read More

Find other two sides and angles of a right angle triangle in C++

sudhir sharma
Updated on 16-Mar-2021 04:52:08

546 Views

In this problem, we are given an integer a denoting one side of a right angle triangle. We need to check whether it is possible to have a right angle triangle with side a. If it is possible, then find the other two sides and angle of a right angle triangle.Let’s take an example to understand the problem, Inputa = 5OutputSides : 5, 12, 13 Angles : 67.38, 22.62, 90ExplanationThe sides of right angle are found as 52 + 122 = 132 And using these sides we can find the angles are, Sin-1 (5/13) and 90 - Sin-1 (5/13).Solution ApproachA ... Read More

Find orientation of a pattern in a matrix in C++

sudhir sharma
Updated on 16-Mar-2021 04:48:58

179 Views

In this problem, we are given a matrix consisting of character values that make a pattern, we are also given a pattern to be found. Our task is to find the orientation (horizontal or vertical) of a pattern in a matrix.Let’s take an example to understand the problem, Inputmat[][] = {    { r, a, m },    {a, m, c},    {w, f, t} } Patern : rawOutputverticalSolution ApproachA simple solution to the problem is by searching the M sized pattern in all the N rows of the matrix. This solution is ok but a more effective solution to ... Read More

C++ program to find numbers with K odd divisors in a given range

sudhir sharma
Updated on 16-Mar-2021 04:45:02

247 Views

In this problem, we are given three integer values, L, R, and k. Our task is to find numbers with K divisors in a given range. We will be finding the count of numbers in the range [L, R] that have exactly k divisors. We will be counting the 1 and the number itself as a divisor.Let’s take an example to understand the problem, Inputa = 3, b = 10, k = 4Output2ExplanationNumbers with exactly 3 divisors within the range 3 to 10 are 6 : divisors = 1, 2, 3, 6 8 : divisors = 1, 2, 4, 8Solution ... Read More

Find numbers with K odd divisors in a given range in C++

sudhir sharma
Updated on 15-Mar-2021 11:11:24

223 Views

In this problem, we are given three integer values, L, R, and k. Our task is to find numbers with K odd divisors in a given range. We will be finding the count of numbers in the range [L, R] that have exactly k divisors.We will be counting the 1 and the number itself as a divisor.Let’s take an example to understand the problem, Inputa = 3, b = 10, k = 3Output2ExplanationNumbers with exactly 3 divisors within the range 3 to 10 are 4 : divisors = 1, 2, 4 9 : divisors = 1, 3, 9Solution ApproachA simple ... Read More

Find number of unique triangles among given N triangles in C++

sudhir sharma
Updated on 15-Mar-2021 11:09:35

327 Views

In this problem, we are given three arrays s1[] , s2[] and s3[] of size N, denoting N triangles. Our task is to find the number of unique triangles among given N triangles.For a triangle to be unique, all its side should be unique i.e. no other triangle should have the same sides.Let’s take an example to understand the problem, Inputs1[] = {1, 5, 3} s2[] = {2, 3, 2} s3[] = {4, 2, 5}Output1ExplanationTriangle with sides 1 2 4 is unique.Solution ApproachA simple solution to the problem is by counting the number of triangles which are unique.For this, we ... Read More

Find number of transformation to make two Matrix Equal in C++

sudhir sharma
Updated on 15-Mar-2021 11:07:22

225 Views

In this problem, we are given two matrices mat1[][] and mat2[][] of the same size. Our task is to find the number of transformations to make two Matrices Equal.The transformation one matrices are −Select any matrix of the two matrices.Select a row or column from the matricesAdd 1 to all elements of the selected row or column.Let’s take an example to understand the problem, Inputmat1[][] = {{1 2} {2 1}} mat1[][] = {{2 3} {4 3}}Output3Explanation1 2 => 2 2 => 2 3 => 2 3 2 1 => 3 1 => 3 2 => 4 3Solution ApproachA simple solution ... Read More

Find number of subarrays with even sum in C++

sudhir sharma
Updated on 15-Mar-2021 11:04:47

383 Views

In this problem, we are given an array arr[] consisting of N elements. Our task is to find the subarray with even sum.Let’s take an example to understand the problem, Inputarr[] = {2, 1, 3, 4, 2, 5}Output28ExplanationThe subarrays are −{2}, {4}, {2}, {2, 4}, {2, 2}, {1, 3}, {1, 5}, {3, 5}, {4, 2}, {2, 1, 3}, {2, 1, 5}, {2, 3, 5}, {2, 4, 2}, {1, 3, 4}, {1, 3, 2}, {1, 4, 5}, {1, 2, 5}, {3, 4, 5}, {3, 2, 5}, {2, 1, 3, 4}, {2, 1, 3, 2}, {2, 3, 4, 5}, {2, 3, 2, ... Read More

Find number of solutions of a linear equation of n variables in C++

sudhir sharma
Updated on 15-Mar-2021 11:03:18

365 Views

In this problem, we are given a linear equation of n variable for the form, coeff1(var1) + coeff2(var2) + … + coeffn(varn) = valueFind the number of solutions of a linear equation of n variables.Let’s take an example to understand the problem, Inputcoeff[] = {3, 1}, value = 4Output1ExplanationEquation : 3x + y = 4. Solution, x = 0, y = 4.Solution ApproachA simple solution to the problem is by evaluating the value of the equation. Then update the values by calling it recursively. If the value is 0, then solution count is 1. Else recur with value by subtracting ... Read More

Advertisements