Found 7197 Articles for C++

Maximize the summation of numbers in a maximum of K moves in range [L, R] in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:45:52

141 Views

We are given an array Arr[] containing integers and 2D array Q containing queries. Each query contains 3 values that are lpos, rpos and K. One can move from index i to next index i+1 in a single step or remain in that index. One can move from lpos to rpos in a maximum of K steps only. Add all numbers at each step including the leftmost number. The goal is to maximize the sum in maximum K moves. If no movement is possible from lpos to rpos in K steps then print “No”. Let us understand more.Let us see ... Read More

Minimum Sum Path In 3-D Array in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:35:04

185 Views

We are given a cube which can be formed using a 3-D array as cube[length][breadth][height]. The task is to calculate the minimum sum path which will be achieved by traversing the cube and hence print the result.Let us see various input output scenarios for this -In − int cube[length][breadth][height] = { { {2, 4, 1}, {3, 4, 5}, {9, 8, 7}}, { {5, 3, 2}, {7, 6, 5}, {8, 7, 6}}, { {3, 2, 1}, {4, 3, 2}, {5, 4, 3}}}Out  − Minimum Sum Path In 3-D Array are: 15Explanation − we are given a cube having length, breadth and height. Now, we ... Read More

Midy’s theorem in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:28:56

240 Views

We are given integer values as a_num that will store the numerator and p_den that will store the denominator which should be a prime number. The task is to check whether the operations performed on a_num after dividing with p_den proves the midy’s theorem or not.Steps to prove Midy’s theorem are-Input numerator as a_num and denominator as p_den which should always be a prime value.Divide the numbers. Check for the repeating decimal values.Store the decimal values until they are not repeating.Check whether the digits are even, if yes, then break them into halvesAdd both the numbers. If the output is ... Read More

Maximum Subarray Sum in a given Range in C++

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

298 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

132 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

306 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

4K+ 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

299 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

292 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

606 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

Advertisements