Find Minimum Speed to Finish All Jobs in C++

sudhir sharma
Updated on 12-Mar-2021 07:09:18

194 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 in C++

sudhir sharma
Updated on 12-Mar-2021 07:05:04

566 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++

sudhir sharma
Updated on 12-Mar-2021 07:01:15

234 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 to Make an Array Beautiful in C++

sudhir sharma
Updated on 12-Mar-2021 06:58:26

584 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

Minimum Merge Operations to Make Array Palindrome in C++

sudhir sharma
Updated on 12-Mar-2021 06:56:17

872 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++

sudhir sharma
Updated on 12-Mar-2021 06:52:40

203 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++

sudhir sharma
Updated on 12-Mar-2021 06:50:39

476 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 of Segment from Given Lengths in C++

sudhir sharma
Updated on 12-Mar-2021 06:46:56

173 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

Find Median in Row-wise Sorted Matrix in C++

sudhir sharma
Updated on 12-Mar-2021 06:44:06

288 Views

In this problem, we are given a 2D array mat[r][c] whose elements are sorted row-wise. Our task is to Find median in a row-wise sorted matrix.Description − we need to find the median of elements of the matrix.Let’s take an example to understand the problem, Inputmat = {    {2, 4, 7},    {5, 6, 8},    {4, 8, 9} }Output6ExplanationThe elements of the matrix stored in array are &minus{2, 4, 4, 5, 6, 7, 8, 8, 9} The median is 6.Solution ApproachA simple solution to the problem is by storing all elements of the array. Then finding the median ... Read More

Find Mean of Subarray Means in a Given Array in C++

sudhir sharma
Updated on 12-Mar-2021 06:41:56

168 Views

In this problem, we are given an array arr[] of size n and an integer m. Our task is to Find mean of subarray means in a given array.Code Description − Here, we need to find the mean of array as the mean of means of subarray of size m.Let’s take an example to understand the problem, Inputarr[] = {2, 5, 3, 6, 1}, m = 3Output3.78ExplanationAll subarrays of size m are {2, 5, 3}, {5, 3, 6}, {3, 6, 1} Means of means of subarray of size m, $$(\left(\frac{2+5+3}{3}\right)+\left(\frac{5+3+6}{3}\right)+\left(\frac{3+6+1}{3}\right))/3=\left(\frac{10}{3}\right)+\left(\frac{14}{3}\right)+\left(\frac{10}{3}\right)/3=34/3/3=3.78$$Solution ApproachA simple solution to the problem is by finding all ... Read More

Advertisements