You are given an integer array perm of length n, where perm is a permutation of the numbers in the range [0, n - 1].
You may swap elements at indices i and j only if
perm[i] AND perm[j] == x,
where AND denotes the bitwise AND operation, and x is a non-negative integer.
Your task is to find the maximum value of x such that it is possible to sort the array perm in non-decreasing order using any number of such allowed swaps.
If the permutation is already sorted, return 0.
Input: perm = [2, 7, 6, 5, 3, 1, 0, 4]
Output: 0
Input: perm = [3, 0, 2, 1]
Output: 0
Accepted:
Submission: