**Maximum AND Sum of Array solution leetcode** – You are given an integer array `nums`

of length `n`

and an integer `numSlots`

such that `2 * numSlots >= n`

. There are `numSlots`

slots numbered from `1`

to `numSlots`

.

You have to place all `n`

integers into the slots such that each slot contains at **most** two numbers. The **AND sum** of a given placement is the sum of the **bitwise** `AND`

of every number with its respective slot number.

- For example, the
**AND sum**of placing the numbers`[1, 3]`

into slotand`1`

`[4, 6]`

into slotis equal to`2`

`(1 AND`

.__1__) + (3 AND__1__) + (4 AND__2__) + (6 AND__2__) = 1 + 1 + 0 + 2 = 4

Return *the maximum possible AND sum of *

`nums`

*given*

`numSlots`

*slots.*

# Maximum AND Sum of Array solution leetcode

Input:nums = [1,2,3,4,5,6], numSlots = 3Output:9Explanation:One possible placement is [1, 4] into slot1, [2, 6] into slot2, and [3, 5] into slot3. This gives the maximum AND sum of (1 AND1) + (4 AND1) + (2 AND2) + (6 AND2) + (3 AND3) + (5 AND3) = 1 + 0 + 2 + 2 + 3 + 1 = 9.

## Maximum AND Sum of Array solution leetcode

Input:nums = [1,3,10,4,7,1], numSlots = 9Output:24Explanation:One possible placement is [1, 1] into slot1, [3] into slot3, [4] into slot4, [7] into slot7, and [10] into slot9. This gives the maximum AND sum of (1 AND1) + (1 AND1) + (3 AND3) + (4 AND4) + (7 AND7) + (10 AND9) = 1 + 1 + 3 + 4 + 7 + 8 = 24. Note that slots 2, 5, 6, and 8 are empty which is permitted.

### Maximum AND Sum of Array solution leetcode

`n == nums.length`

`1 <= numSlots <= 9`

`1 <= n <= 2 * numSlots`

`1 <= nums[i] <= 15`