Problem
Ask
Submissions

Problem: Maximum Value at a Given Index in a Bounded Array

Medium
30 min
Explore how to apply modified binary search to find the maximum value at a specific index in a bounded array. Understand the constraints on array elements and sum, and learn to construct an array that meets these conditions while maximizing the value at the target index.

Statement

Given three positive integers, n, index, and maxSum, output the nums[index] by constructing an array of nums with the length of n, which satisfies the following conditions:

  • The length of the array nums is equal to n.

  • Each element nums[i] is a positive integer, where 11\leq i <\lt n.

  • The absolute difference between two consecutive elements, nums[i] and nums[i+1], is at most 11.

  • The sum of all elements in nums does not exceed maxSum.

  • The element at nums[index] contains the maximum value.

Constraints:

  • 11\leqn \leqmaxSum \leq10910^9

  • 00\leqindex <\ltn

Problem
Ask
Submissions

Problem: Maximum Value at a Given Index in a Bounded Array

Medium
30 min
Explore how to apply modified binary search to find the maximum value at a specific index in a bounded array. Understand the constraints on array elements and sum, and learn to construct an array that meets these conditions while maximizing the value at the target index.

Statement

Given three positive integers, n, index, and maxSum, output the nums[index] by constructing an array of nums with the length of n, which satisfies the following conditions:

  • The length of the array nums is equal to n.

  • Each element nums[i] is a positive integer, where 11\leq i <\lt n.

  • The absolute difference between two consecutive elements, nums[i] and nums[i+1], is at most 11.

  • The sum of all elements in nums does not exceed maxSum.

  • The element at nums[index] contains the maximum value.

Constraints:

  • 11\leqn \leqmaxSum \leq10910^9

  • 00\leqindex <\ltn