Minimum Array End

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 than nums[i], and the result of the bitwise AND operation between all elements of nums is x.

Return the minimum possible value of nums[n - 1].

Example 1
Inputn = 3, x = 4
Output6
nums can be [4, 5, 6] and its last element is 6.
Example 2
Inputn = 2, x = 7
Output15
nums can be [7, 15] and its last element is 15.

Constraints

  • 1 <= n, x <= 10^8

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate