Menu
Coddy logo textTech

Find Minimum Sum

Lesson 17 of 17 in Coddy's Bit Manipulation course.

challenge icon

Challenge

Medium

You are given an array <strong>a</strong> of size <strong>n</strong>.

You can perform the following operation on the array:

  • Choose two different integers <strong>i</strong> , <strong>j</strong> (1 ≤ i < j ≤ n), replace <strong>a<sub>i</sub></strong> with <strong>x</strong> and <strong>a<sub>j</sub></strong> with <strong>y</strong>. In order not to break the array, the condition <strong>a<sub>i </sub>| a<sub>j </sub>= x | y</strong> must be held, where <strong>|</strong> denotes the bitwise OR operation. Notice that <strong>x</strong> and <strong>y</strong> are non-negative integers.

Please output the minimum sum of the array you can get after using the operation above any number of times.

Try it yourself

#include <vector>
using namespace std;

int FindMinSum(vector<int> a) {
    // Write code here
}

All lessons in Bit Manipulation