Skip to content

Commit 738b4d3

Browse files
committed
Added README.md file for Sum of All Subset XOR Totals
0 parents  commit 738b4d3

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<h2><a href="https://leetcode.com/problems/sum-of-all-subset-xor-totals">Sum of All Subset XOR Totals</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
2+
3+
<ul>
4+
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
5+
</ul>
6+
7+
<p>Given an array <code>nums</code>, return <em>the <strong>sum</strong> of all <strong>XOR totals</strong> for every <strong>subset</strong> of </em><code>nums</code>.&nbsp;</p>
8+
9+
<p><strong>Note:</strong> Subsets with the <strong>same</strong> elements should be counted <strong>multiple</strong> times.</p>
10+
11+
<p>An array <code>a</code> is a <strong>subset</strong> of an array <code>b</code> if <code>a</code> can be obtained from <code>b</code> by deleting some (possibly zero) elements of <code>b</code>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> nums = [1,3]
18+
<strong>Output:</strong> 6
19+
<strong>Explanation: </strong>The 4 subsets of [1,3] are:
20+
- The empty subset has an XOR total of 0.
21+
- [1] has an XOR total of 1.
22+
- [3] has an XOR total of 3.
23+
- [1,3] has an XOR total of 1 XOR 3 = 2.
24+
0 + 1 + 3 + 2 = 6
25+
</pre>
26+
27+
<p><strong class="example">Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> nums = [5,1,6]
31+
<strong>Output:</strong> 28
32+
<strong>Explanation: </strong>The 8 subsets of [5,1,6] are:
33+
- The empty subset has an XOR total of 0.
34+
- [5] has an XOR total of 5.
35+
- [1] has an XOR total of 1.
36+
- [6] has an XOR total of 6.
37+
- [5,1] has an XOR total of 5 XOR 1 = 4.
38+
- [5,6] has an XOR total of 5 XOR 6 = 3.
39+
- [1,6] has an XOR total of 1 XOR 6 = 7.
40+
- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.
41+
0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28
42+
</pre>
43+
44+
<p><strong class="example">Example 3:</strong></p>
45+
46+
<pre>
47+
<strong>Input:</strong> nums = [3,4,5,6,7,8]
48+
<strong>Output:</strong> 480
49+
<strong>Explanation:</strong> The sum of all XOR totals for every subset is 480.
50+
</pre>
51+
52+
<p>&nbsp;</p>
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li><code>1 &lt;= nums.length &lt;= 12</code></li>
57+
<li><code>1 &lt;= nums[i] &lt;= 20</code></li>
58+
</ul>

0 commit comments

Comments
 (0)