Skip to main content
Back to problems
Leetcode
Medium
Arrays
Bit Manipulation
Math
Google
Minimum Array End

Find the smallest possible last value of an increasing array after fixing the first element and the length.

Acceptance 0%
Problem Statement

You are given two integers, nn and xx.

Construct a strictly increasing array of length nn such that:

  • the first element is xx,
  • the array uses positive integers,
  • and among all valid arrays, the last element is as small as possible.

Return that minimum possible last element.

A useful way to think about the problem is that you are not asked to output the whole array, only the smallest achievable ending value for a valid increasing sequence starting at xx.

This problem is about how the binary representation of numbers can be used to place the additional n1n-1 elements while keeping the final value minimal.

Input Format

  • A single test case is given.
  • Two integers are provided: nn and xx.

Output Format

  • Return the minimum possible last element of a valid strictly increasing array of length nn whose first element is xx.

Constraints

  • 1n1 \le n
  • 1x1 \le x
  • The answer may require 64-bit integer arithmetic.
Examples
Sample cases returned by the problem API.

Example 1

Input

n = 3, x = 4

Output

6

Explanation

One optimal array is [4, 5, 6]. The last value is 6, and no valid array of length 3 starting with 4 can end smaller.

Example 2

Input

n = 4, x = 2

Output

7

Explanation

One optimal array is [2, 3, 6, 7]. The ending value 7 is minimal among all valid choices.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.