Lexicographically Maximal Prefix AND
You are given an array $A$ of size $N$. You can rearrange the elements of $A$ as you want. After that, construct an array $B$ of size $N$ as: - $B_1 = A_1$; - $B_i = B_{i - 1}$ $\&$ $A_i$ for all $2 \le i \le N$, where $\&$ denotes the [bitwise AND operator](https://en.wikipedia.org/wiki/Bitwise_operation#AND). Find the **lexicographically largest** possible array $B$. For two arrays $X$ and $
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start