Found 7347 Articles for C++

Find mirror of a given node in Binary tree in C++

Naveen Singh
Updated on 12-Mar-2021 07:28:27

142 Views

In this problem, we are given a binary tree. Our task is to Find mirror of a given node in the Binary tree. We will be given a node, and find the mirror image of that node in the opposite subtree.Let’s take an example to understand the problem, InputOutputmirror of B is E.Solution ApproachOne simple solution to solve the problem is by using the recursion from the root using two pointers for left subtree and right subtree. Then for the target value if any mirror is found return the mirror otherwise recur other nodes.Program to illustrate the working of our ... Read More

Find mirror image of a point in 2-D plane in C++

Naveen Singh
Updated on 12-Mar-2021 07:24:48

201 Views

In this problem, we are given a point P in a 2-D plane and the points a, b, c of the equation ax + by + c = 0. Our task is to find a mirror image of a point in 2-D plane.Let’s take an example to understand the problem, InputP = (2, 1), a = 1, b = -1, c = 0Output(1, 2)ExplanationThe plane looks like, Solution ApproachTo solve the problem, we need to find the equation point P' with coordinates (x', y'). So, we have R, the midpoint where the line form P - P' intersects the mirror ... Read More

Find minimum speed to finish all Jobs in C++

Naveen Singh
Updated on 12-Mar-2021 07:09:18

121 Views

In this problem, we are given an array arr[] consisting of n elements and an integer h. Each element of the array arr[] contains the number of pending jobs for the person and H is the time left to complete the jobs (in Hours). Our task is to Find minimum speed to finish all Jobs.Problem Description: We need to find the number of jobs the person needs to complete in one hour in order to complete all the jobs given in the array in H hours. If he can complete all specified at arr[i] in less than an hour, we ... Read More

Find minimum possible size of array with given rules for removing elements in C++

Naveen Singh
Updated on 12-Mar-2021 07:05:04

471 Views

In this problem, we are given an array of n numbers and an integer value k. Our task is to Find minimum possible size of the array with given rules for removing elements.Problem Description − we need to minimise the number of elements in the array. By using the follow deletion operation, The number of elements that can be removed at once is 3. The removal is possible if the three elements satisfy the two given conditions, Cond 1 − Three elements should be adjacent.>Cond 2 − the difference between two nearby elements is k, i.e. arr[i + 1] = ... Read More

Find minimum possible digit sum after adding a number d in C++

Naveen Singh
Updated on 12-Mar-2021 07:01:15

161 Views

In this problem, we are given two numbers n and d. Our task is to Find the minimum possible digit sum after adding a number d.Problem Description − we need to minimise the digits sum by adding kth multiple of d to n.Let’s take an example to understand the problem, Inputn = 5230, d = 54Output1ExplanationThe number will be 5230 + (2*54) = 5338Solution ApproachA simple approach to solve the problem would be to check all multiples of d from 1 to 8, as at 9th multiple the sum of digits will repeat. This is based on modulo 9, which ... Read More

Find minimum operations needed to make an Array beautiful in C++

Naveen Singh
Updated on 12-Mar-2021 06:58:26

481 Views

In this problem, we are given a binary array bin[] consisting n binary values which happen to be 0 and 1. Our task is to find minimum operations needed to make an Array beautiful.Beautiful array is a special type of binary array which consists of a pattern of alternate 0’s and 1’s.Problem Description − We need to find the number operations that are required to make the array beautiful. An operations consists of these steps −Step 1 − Cut the array into two halves.Step 2 − Reverse any one of the two halves.Step 3 − Join then halves back.We will ... Read More

Find minimum number of merge operations to make an array palindrome in C++

Naveen Singh
Updated on 12-Mar-2021 06:56:17

657 Views

In this problem, we are given an array arr[] consisting of n positive numbers. Our task is to Find minimum number of merge operations to make an array palindrome.Palindrome array are similar to palindrome strings, the elements at index i and n-i should be the same.Example{5, 1, 7, 2, 7, 1, 5}Problem Description − We need to make the array palindrome by performing operations on it. And the only operation which is valid on the array is the merge operation in which we will add elements at index i and i+1.We need to return the minimum number of such operations ... Read More

Find minimum in an array without using Relational Operators in C++

Naveen Singh
Updated on 12-Mar-2021 06:52:40

120 Views

In this problem, we are given an array arr[] consisting of n positive elements. Our task is to find minimum in an array without using Relational Operators.Relational operators in programming are those operators which are used to check the relationship between two values. Like == (equals), greater than (>), less than (

Find Minimum Depth of a Binary Tree in C++

Naveen Singh
Updated on 12-Mar-2021 06:50:39

340 Views

In this problem, we are given a binary tree. Our task is to Find Minimum Depth of a Binary Tree.Binary Tree has a special condition that each node can have a maximum of two children.The minimum depth of a binary tree is the shortest path between the root node to any leaf node.Let’s take an example to understand the problem, InputOutput2Solution ApproachThe solution to the problem is by traversing the binary tree and counting the heights. This can be done by recursively calling for the child node of the node for each node non-leaf node and return 1 for each ... Read More

Find middle point segment from given segment lengths in C++

Naveen Singh
Updated on 12-Mar-2021 06:46:56

116 Views

In this problem, we are given an array arr[] of size m representing the lengths of line segments.The line segments are from 0 to arr[0] , arr[0] to arr[1] and so on. Our task is to find the segment which is at the middle of all segments.Let’s take an example to understand the problem, Inputarr[] = {5, 7, 13}Output3ExplanationSegments are : (0, 5) , (5, 12), (12, 25)Solution ApproachTo solve the problem, we will find the middle point of the line by (arrSum/2). If this middle point is a starting or ending point of a line segment then print -1. ... Read More

Advertisements