Found 7347 Articles for C++

Maximum Subarray Sum in a given Range in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:23:39

240 Views

We are given with an array of integer elements of any given size. The task is to find the maximum sum which will be calculated by forming the subarrays from the given array within the given range which can be started from any possible index value in an array.Let us see various input output scenarios for this -In − int arr[] = { 3, 2, -1, 6, 7, 2 }, int first = 0, int last = 5Out − Maximum Subarray Sum in a given Range is: 19Explanation − we are given with an array containing both positive and negative values and a ... Read More

Minimize the sum of roots of a given polynomial in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:18:10

66 Views

We are given with an array of integer elements representing the coefficient values of a polynomial. The size of an array will be ‘n’ i.e. number of elements in an array. The degree of polynomial always starts with n-1 as there will be one constant value at the end of the polynomial series. The task is to replace the coefficient with other polynomials in such a manner that sum of roots will be minimized.Let us see various input output scenarios for this -In − int arr[] = { 2, -1, 4, 9, -1, 10, -5}Out − Minimize the sum of roots of ... Read More

Minimum Word Break Problem in C++

Sunidhi Bansal
Updated on 22-Oct-2021 07:57:01

191 Views

We are given an array string of words of any given size and the task is to break the words in all possible ways such that after the break the string formed should be a valid string and we have to calculate all such minimum word break as per the problem.Let us see various input output scenarios for this -In − string word[] = {"Hello", "Hell", "tell", "well", "bell", "ball", "all" }Out − Minimum Word Break is: 1Explanation − we are given with multiple words. Now we will pass the concatenation of two strings i.e. Hell and all and will break the concatenated ... Read More

Mid-Point Line Generation Algorithm in C++

Sunidhi Bansal
Updated on 22-Oct-2021 07:49:54

3K+ Views

A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line on a screen and in terms of graphics we refer to the points as pixels and every pixel is associated with integer coordinates. We are given integer coordinates in the form of (x1, y1) and (x2, y2) where, x1 < x2 and y1 < y2. The task is to calculate all the mid-points between point 1 i.e. (x1, y1) and point 2 i.e. (x2, y2) using the Midpoint Line Generation Algorithm.There are three ... Read More

Maximize the subarray sum after multiplying all elements of any subarray with X in C++

Sunidhi Bansal
Updated on 22-Oct-2021 07:42:24

179 Views

We are given with an integer array and an integer variable i.e. ‘X’. The task is to firstly form the subarray from the given array and then multiply all the elements of a subarray with an integer X. At last find out the elements that will contribute the maximum sum.Let us see various input output scenarios for this -In − int arr[] = {2, 4, 1, -5, -2}, X = 3Out  − Maximize the subarray sum after multiplying all elements of any subarray with X are: 21Explanation − we are given with an array and an integer variable as X. Firstly, ... Read More

Maximize the sum of array by multiplying prefix of array with -1 in C++

Sunidhi Bansal
Updated on 22-Oct-2021 07:30:50

212 Views

We are given an integer array and the task is to firstly fetch the prefix of an array and then multiply it with -1, secondly calculate the prefix sum of an array and lastly find the maximum sum from the prefix array generated.Prefix array is generated as −First element of prefixArray[0] = first element of an arraySecond element of prefixArray[1] = prefixArray[0] + arr[1]Third element of prefixArray[2] = prefixArray[1] + arr[2]Fourth element of prefixArray[3] = prefixArray[2] + arr[3] …..etc.Let us see various input output scenarios for this -In − int arr[] = {2, 4, 1, 5, 2}Out − Prefix array is: ... Read More

Minimum sum submatrix in a given 2D array in C++

Sunidhi Bansal
Updated on 22-Oct-2021 06:40:12

432 Views

We are given a 2-D array of integer elements forming the matrix. The task is to calculate the count of minimum sum by pulling the submatrix from the matrix so formed.Let us see various input output scenarios for this -In −int matrix[size][size] = { {2, 3, -1, 5}, {-2, 9, -1, 6}, { 5, 6, 9, -9}, { -6, 1, 1, 1} }Out −Minimum sum submatrix in a given 2D array is: -9Explanation −we are given a 2-D array of size 4x4 i.e. 4 rows and 4 columns. Now, we will find out the sub-matrix from the given matrix such ... Read More

Minimum no. of iterations to pass information to all nodes in the tree in C++

Sunidhi Bansal
Updated on 21-Oct-2021 13:41:59

580 Views

We are given a tree data structure with ‘n’ number of nodes. The given tree will have a root node and respective children which can be any number and further child can have any number of children. The task is to find the minimum number of iterations required by a root node of a tree to pass the information to all nodes in a tree. At a time, a node can pass information to one of its children and further one of its children can pass information to one of its children and meanwhile root node can pass information to ... Read More

Minimum 1s to lend power to make whole array powerful using C++

Sunidhi Bansal
Updated on 21-Oct-2021 12:20:54

50 Views

We are given a binary array which can store digits 1’s and 0’s of any given size and an integer variable let’s say, base. The task is to calculate the minimum 1’s that can lend power to other elements of a binary array such that the entire array becomes powerful. An element can lend power to its adjacent element or any other elements within the distance less than base.Let us see various input output scenarios for this -In − int arr[] = {1, 1, 0, 1, 1, 0, 1}, int base = 7Out −Minimum 1s to lend power to make ... Read More

C++ Program to find out the distinct elements in a given sequence

Arnab Chakraborty
Updated on 20-Oct-2021 08:18:48

285 Views

Suppose we are given three integer numbers n, x, y, and z. We have to make a sequence from the given integers where the first item of the sequence is (x modulo 231). Other than the first element, other elements in the sequence ai = (a(i-1) * y + z) modulo 231 , where 1 ≤ i ≤ n - 1. We have to find out the number of distinct integers in the sequence we made.So, if the input is like n = 5, x = 1, y = 2, z = 1, then the output will be 5.The unique ... Read More

Advertisements