Minimum Array End - Problem
You are given two integers n and x. You have to construct an array of positive integers nums of size n where:
- For every
0 <= i < n - 1,nums[i + 1]is greater thannums[i] - The result of the bitwise AND operation between all elements of
numsisx
Return the minimum possible value of nums[n - 1].
Input & Output
Example 1 — Basic Case
$
Input:
n = 3, x = 4
›
Output:
6
💡 Note:
Array [4,5,6] has AND = 4 & 5 & 6 = 4, strictly increasing, minimum last element is 6
Example 2 — Single Element
$
Input:
n = 1, x = 2
›
Output:
2
💡 Note:
Array [2] has AND = 2, only one element so result is 2
Example 3 — Larger Case
$
Input:
n = 4, x = 1
›
Output:
7
💡 Note:
Array [1,3,5,7] has AND = 1 & 3 & 5 & 7 = 1, strictly increasing, minimum last element is 7
Constraints
- 1 ≤ n ≤ 108
- 1 ≤ x ≤ 108
Visualization
Tap to expand
Understanding the Visualization
1
Input
n=3 numbers needed, AND result must be x=4
2
Constraint
Array must be strictly increasing and AND = x
3
Output
Minimum possible last element
Key Takeaway
🎯 Key Insight: Use x as a bit template and fill zero positions with binary patterns to create minimal increasing sequence
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code