Maximum Possible XOR of Every Element in an Array with Another Array in C++

Narendra Kumar
Updated on 03-Jun-2020 08:23:31

417 Views

In this problem, we are given two arrays A and B of n elements each. Our task is to create a program to find the maximum possible XOR of every element in an array with another array.We have to compute the maximum XOR for each element of array A with array B i.e. for each element of array A we will select an element in array B which will have the maximum XOR value.Let's take an example to understand the problem −Input −array A = {3, 6 ,11, 9} array B = {8, 2, 4, 1}Output −11 14 15 13Explanation−Let’s ... Read More

Maximum Primes Whose Sum is Equal to Given n in C++

Narendra Kumar
Updated on 03-Jun-2020 08:21:44

193 Views

In this problem, we are given a number n. Our task is to find the maximum count of primes whose sum is equal to given N.Here, we will find the maximum number of prime numbers that when added will be equal to the number.The prime number are those number which can be divide by either themselves or one.let's take an example to understand the problem −Input − N = 9Output − 4Explanation −9 can be repressed as the sum of prime numbers in the following ways: 2, 2, 2, 3 3, 3, 3 2, 2, 5 2, 7 Out of ... Read More

Maximum Removal from Array When Removal Time Waiting Time in C++

Narendra Kumar
Updated on 03-Jun-2020 08:20:38

133 Views

In this problem, we are given an array of N elements. Our task is to find the maximum removal from the array when removal time >= waiting time.So, here we will be removing the elements of the array. The value of the element of the array denotes the removal time(time taken to remove the element from the array).The element has a waiting time which is the time it will have to wait till it will get removed.The element can be removed from the only if the removal time is greater than the time it has to wait.We have to find ... Read More

Maximum Segment Value After Putting K Breakpoints in a Number in C++

Narendra Kumar
Updated on 03-Jun-2020 08:19:11

274 Views

In this problem, we are given a string that denotes a large number and an integer k roar denotes the number of breakpoints. Our task is to create a program that will find the maximum segment value after putting L breakpoints in a number.Here, we have to find the maximum number that can be generated after putting k breakpoint in the number given by the string.Let's take an example to understand the problemInput − string = “45972”, k = 3Output − 97Explanation −All possible number is: 45    9    7    2 4    59    7    2 ... Read More

Maximum Spiral Sum in Binary Tree in C++

Narendra Kumar
Updated on 03-Jun-2020 08:17:12

183 Views

In this problem, we are given a binary tree. Our task is to create a program that will find the maximum spiral sum in a binary tree in C++.Spiral sum of a binary tree is the sum of nodes that are encountered in the spiral traversal of the binary tree.In the spiral traversal of a tree, the nodes are traversed from the root to the leaf node. The traversal takes place from left to right then for the next level from right to left and so on for the further levels.Example −Output −5Explanation −We will consider the spiral traversal until the ... Read More

Maximum Steps to Transform 0 to X with Bitwise AND in C++

Narendra Kumar
Updated on 03-Jun-2020 08:14:40

163 Views

In this problem, we are given an integer X. Our task is to find the total number of steps that are taken to transform from 0 to X.Valid transformation − One step is counted when one transformation takes place from A to B. The condition for the transform to take place is A != B and A & B = A (& is bitwise AND). So, 1 step is transforming from A to B and we have to create a program that will count the maximum number of steps to transform 0 to X.Let’s take an example to understand the ... Read More

Maximum Subarray Sum After Inverting At Most Two Elements in C++

Narendra Kumar
Updated on 03-Jun-2020 08:13:04

322 Views

In this problem, we are given an array. Our task is to create a program that will find the maximum subarray sum after inverting at most two elements in C++.Problem description − Here, we can have to find the subarray that will produce the maximum sum on inverting the sign of any two numbers of the array.Let’s take an example to understand the problem, Input − array = {-5, 1, 3, 8, -2, 4, 7}Output − 30Explanation − we will consider elements from index 0 to 6 and invert values -5 and -2 to get the array with max sum.To ... Read More

Maximum Subarray Sum by Flipping Signs of At Most K Array Elements in C++

Narendra Kumar
Updated on 03-Jun-2020 08:11:19

473 Views

In this problem, we are given an array and an integer k. Our task is to create a program that will find the maximum subarray sum by flipping signs of at most k array elements in C++.Code description − Here, we will have to find at most k elements to flip in the array which will make the sum of subarray created from this array maximum.Let’s take an example to understand the problem, Input − array = {1, -2, 7, 0} k = 2Output − 10Explanation − we will flip only one element which is -2, it makes the array ... Read More

Maximum Subarray Sum in Array Formed by Repeating the Given Array k Times in C++

Narendra Kumar
Updated on 03-Jun-2020 08:08:33

208 Views

In this problem, we are given an array and a number k. Our task is to create a program that will find the maximum subarray sum in an array formed by repeating the given array k time in c++.Problem description − Here, we will find the maximum sum of the subarray formed from array formed by repeating the given array k times.Let’s take an example to understand the problem, Input − array = {3, 5, 1} k = 2Output − 18Explanation −array formed by repeating k times, array = {3, 5, 1, 3, 5, 1} Maximum subarray sum = 3+5+1+3+5+1 ... Read More

Maximum Subarray Sum Modulo M in C++

Narendra Kumar
Updated on 03-Jun-2020 08:06:42

488 Views

In this problem, we are given an array of size n and an integer m. our task is to create a program that will find the maximum subarray sum modulo m in C++.Program description − Here, we will find the maximum value obtained by dividing the sum of all elements of subarray divided by m.Let’s take an example to understand the problem, Input − array = {4, 9 ,2} m = 6Output − 5Explanation − All subarrays and their remainders on dividing{4}: 4%6 = 4 {9}: 9%6 = 3 {2}: 2%6 = 2 {4, 9}: 13%6 = 1 {9, 2}: ... Read More

Advertisements