FastPrepMaximum Sum of Non-Adjacent Elements
Problems/Maximum Sum of Non-Adjacent Elements

Maximum Sum of Non-Adjacent Elements

LSEG logoLSEG● EasyFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported non-consecutive maximum-sum task matches at about 85%. Empty selection, negative-value behavior and numeric bounds are exercise conventions omitted from the report.

Choose any number of elements from the integer array nums so that no two chosen indices are consecutive.

Return the maximum possible sum. You may choose no elements; that choice has sum 0. There is no fixed selection count.

Function

maxNonAdjacentSum(nums: int[]) → long

Examples

Example 1

nums = [2,7,9,3,1]return = 12

Choose indices 0, 2 and 4: 2 + 9 + 1 = 12.

Example 2

nums = [-4,-2,-9]return = 0

Choosing no elements gives 0, which is greater than every nonempty allowed sum.

Example 3

nums = []return = 0

The empty array permits only the empty selection.

Constraints

  • 0 <= nums.length <= 100000.
  • -1000000000 <= nums[i] <= 1000000000.

Interview reports that mention this question

  • LSEG Graduate Technology OA and Interviews: 7 Experiences
See LSEG hiring insights
Saved
class Solution {
    public long maxNonAdjacentSum(int[] nums) {
            // write your code here
        }
}
Checking account…