Bitwise XOR Flashcards

(6 cards)

1
Q

What is Bitwise XOR and when is it used?

A

Definition: Uses XOR to find unique or missing elements.

Use Case: Single number, missing numbers.

Example: [No LeetCode match, course example: Single Number].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the key steps for Bitwise XOR?

A

Steps:
1. Initialize result=0.
2. XOR all elements.
3. Result is unique element.

Action: Explain steps for Single Number aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does Bitwise XOR apply to Single Number?

A

**Problem: **Find number appearing once in array.

**Approach: **XOR all numbers; pairs cancel, leaving single number.

Example: Single Number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the complexity and gotchas of Bitwise XOR?

A

**Complexity: **Time: O(n), Space: O(1).

**Gotchas: **Empty array, no single number.

Action: List edge cases for Single Number aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Code example for Bitwise XOR.

A

```python
from typing import List

def single_number(nums: List[int]) -> int:
result = 0
for num in nums:
result ^= num
return result
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Visual for Bitwise XOR.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly