Find Xor-Beauty of Array — LeetCode 2527 Python Solution
MediumBit ManipulationArrayMath
- Problem
- #2527
- Pattern
- Bit Manipulation
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given a 0-indexed integer array nums. The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).
Example
- Input
- nums = [1,4]
- Output
- 5
- Explanation
- The triplets and their corresponding effective values are listed below:
Python solution
Python
class Solution:
def xorBeauty(self, nums: List[int]) -> int:
return reduce(xor, nums)Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1), where n is the length of the array auxiliary |
Pattern: Bit Manipulation
Use XOR, masks and the low-bit trick to replace whole data structures with an integer. LeetCode 2527. Find Xor-Beauty of Array is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Bit Manipulation.
The bit manipulation guide has the Python template for the pattern and the 194 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2527. Find Xor-Beauty of Array?
- LeetCode 2527. Find Xor-Beauty of Array is rated Medium on LeetCode.
- What is the time complexity of LeetCode 2527. Find Xor-Beauty of Array?
- The Python solution on this page runs in O(n).
- What is the space complexity of LeetCode 2527. Find Xor-Beauty of Array?
- The Python solution on this page uses O(1), where n is the length of the array auxiliary space.
- What topics does LeetCode 2527. Find Xor-Beauty of Array cover?
- LeetCode 2527. Find Xor-Beauty of Array is tagged Bit Manipulation, Array and Math on LeetCode.