Maximize the Value of Given Expression in C++

Narendra Kumar
Updated on 24-Dec-2019 07:17:59

332 Views

Problem statementGiven three non-zero integers a, b and c. The task is to find the maximum value possible by putting addition and multiplication signs between them in any order.Please note that rearrangement of integers is allowed but addition and multiplication sign must be used once.If a = 1, b = 3 and c = 5 then maximum value will be 20 as follows−(1 + 3) * 5 = 20Algorithm1. If all numbers are positive, then add two small numbers and multiply result with larger one 2. If only two numbers are positive, then multiply 2 positive numbers and add remaining ... Read More

Maximize the Sum of arr[i] in C++

Narendra Kumar
Updated on 24-Dec-2019 07:15:21

470 Views

Problem statementGiven an array of N integers. You are allowed to rearrange the elements of the array. The task is to find the maximum value of Σarr[i]*i, where i = 0, 1, 2, .. n – 1.If input array = {4, 1, 6, 2} then the maximum sum will be 28 if we rearrange elements in sorted order−{1, 2, 4, 6} = (1 * 0) + (2 * 1) + (4 * 2) + (6 * 3) = 28Algorithm1. Sort array in ascending order 2. Iterate over array and multiply each array element by 1 where i = 0, 1, ... Read More

Maximize Number of Segments of Length p, q, and r in C++

Narendra Kumar
Updated on 24-Dec-2019 07:12:10

210 Views

Problem statementGiven a rod of length L, the task is to cut the rod in such a way that the total number of segments of length p, q and r is maximized. The segments can only be of length p, q, and rIf l = 15, p = 2, q = 3 and r = 5 then we can make 7 segments as follows −{2, 2, 2, 2, 2, 2, 3}AlgorithmWe can solve this problem using dynamic programming1. Initialize dp[] array to 0 2. Iterate till the length of the rod. For every i, a cut of p, q and ... Read More

Maximize the Number by Rearranging Bits in C++

Narendra Kumar
Updated on 24-Dec-2019 07:09:42

180 Views

Problem statementGiven an unsigned number, find the maximum number that could be formed by using the bits of the given unsigned numberIf the input number is 8 then its binary representation is−00000000000000000000000000001000To maximize it set MSB to 1. Then number becomes 2147483648 whose binary representation is−10000000000000000000000000000000Algorithms1. Count number of set bits in the binary representation of a given number 2. Find a number with n least significant set bits 3. shift the number left by (32 – n)Example Live Demo#include using namespace std; unsigned getMaxNumber(unsigned num){    int n = __builtin_popcount(num);    if (n == 32) {       return num;    }    unsigned result = (1

Maximize the Median After Adding K Elements to an Array in C++

Narendra Kumar
Updated on 24-Dec-2019 07:07:25

350 Views

Problem statementGiven an array arr[] of N elements and an integer K where K < N. The task is to insert K integer elements to the same array such that the median of the resultant array is maximizedIf input array is {1, 3, 2, 5} and k = 3 then −Sorted array becomes {1, 2, 3, 5}Insert 3 elements that are greater than 5. After this operation array becomes {1, 2, 3, 5, 6, 6, 6}Median of the new array is 5Algorithm1. In order to maximize the median of the resultant array, all the elements that need to be inserted ... Read More

Maximize the Median of an Array in C++

Narendra Kumar
Updated on 24-Dec-2019 07:05:41

263 Views

Problem statementGiven an array arr[] of N elements and an integer K where K < N. The task is to insert K integer elements to the same array such that the median of the resultant array is maximizedIf input array is {1, 3, 2, 5} and k = 3 then−Sorted array becomes {1, 2, 3, 5}Insert 3 elements that are greater than 5. After this operation array becomes {1, 2, 3, 5, 6, 6, 6}Median of the new array is 5Algorithm1. In order to maximize the median of the resultant array, all the elements that need to be inserted must ... Read More

PHP Soap Client Not Supporting WSDL Extension in SAP Connection

Hayat Azam
Updated on 24-Dec-2019 07:03:28

473 Views

The possible solution could be to update policy tag like thisUpdate the policy tag like this:And try the serviceAnother possible option is to change /ws_policy/ to /standard/ and you will be able to use PHP Soap Client to consume Web Service.Go to Web Service Administration in your SAP ECC system using SOAMANAGER -> SOA-ManagementIn URL of the browser, you can see the “ws_policy” tag -> replace this with “standard” and you will have WSDL without policy tag.

Maximize Maximum Subarray Sum After Removing One Element in C++

Narendra Kumar
Updated on 24-Dec-2019 07:03:04

318 Views

Problem statementGiven an array arr[] of N integers. The task is to first find the maximum sub-array sum and then remove at most one element from the sub-array. Remove at most a single element such that the maximum sum after removal is maximized.If given input array is {1, 2, 3, -2, 3} then maximum sub-array sum is {2, 3, -2, 3}. Then we can remove -2. After removing the remaining array becomes−{1, 2, 3, 3} with sum 9 which is maximum.Algorithm1. Use Kadane’s algorithm to find the maximum subarray sum. 2. Once the sum has beens find, re-apply Kadane’s algorithm ... Read More

Maximize the Bitwise OR of an Array in C++

Narendra Kumar
Updated on 24-Dec-2019 06:59:33

843 Views

Problem statementGiven an array of N integers. The bitwise OR of all the elements of the array has to be maximized by performing one task. The task is to multiply any element of the array at-most k times with a given integer xIf input array is {4, 3, 6, 1}, k = 2 and x = 3 then maximum value can be obtained is 55Algorithm1. multiply an array element with (x^k) and do bitwise OR it with the bitwise OR of all previous elements 2. Multiply an array element with bitwise OR of all next elements 3. Return the maximum ... Read More

Maximize Number of 0s by Flipping a Subarray in C++

Narendra Kumar
Updated on 24-Dec-2019 06:57:49

784 Views

Problem statementGiven a binary array, find the maximum number of zeros in an array with one flip of a subarray allowed. A flip operation switches all 0s to 1s and 1s to 0sIf arr1= {1, 1, 0, 0, 0, 0, 0}If we flip first 2 1’s to 0’s, then we can get subarray of size 7 as follows −{0, 0, 0, 0, 0, 0, 0}Algorithm1. Consider all subarrays and find a subarray with maximum value of (count of 1s) – (count of 0s) 2. Considers this value be maxDiff. Finally return count of zeros in original array + maxDiff.Example Live Demo#include ... Read More

Advertisements