Dsa
Arrays
Easy
Maximize Non-Adjacent Sum
Given an array of integers, return the maximum sum of non-adjacent elements. Numbers can be 0 or negative, and you cannot pick two adjacent numbers. If the array is empty, return 0.
Input Format:
- The first line contains an integer n (0 ≤ n ≤ 100), the size of the array.
- The second line contains n space-separated integers representing the elements of the array.
Output Format:
- Print the maximum sum of non-adjacent elements.
Example:
Input:
5
5 1 1 5
Output:
10
Key concepts
arraysdynamic programmingnon-adjacent
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now