Problem ยท Dynamic Programming

Maximum Sum of Balanced Subsequence ๐Ÿฎ

Learn this problem
โ— MediumSNService NowOA

Problem statement

You are given a 0-indexed integer array nums.

A subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:

nums[i] - nums[i-1] == i - (i-1),

A subsequence of nums having length 1 is considered balanced.

Return an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.

A subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.

Function

maxSumOfBalancedSubsequence(nums: int[]) โ†’ int

Examples

Example 1

nums = [1, 2, 3]return = 6
Explanation not found ๐Ÿ‘‰๐Ÿ‘ˆ

Example 2

nums = [3, 2, 1]return = 3
Explanation not found ๐Ÿ‘‰๐Ÿ‘ˆ

Constraints

Constraints not found ๐Ÿ‘‰๐Ÿ‘ˆ

More Service Now problems

drafts saved locally
public int maxSumOfBalancedSubsequence(int[] nums) {
    // write your code here
}
nums[1, 2, 3]
expected6
checking account