Dsa
Dynamic Programming
Medium
Maximum Non-Adjacent Sum
Given an array of non-negative integers, you need to find the maximum sum of non-adjacent elements. You cannot pick two adjacent elements in the array. Write a function that accepts an array of integers and returns the maximum sum possible.
Input format:
- The first line contains an integer n, the number of elements in the array.
- The second line contains n space-separated integers, the elements of the array.
Output format:
- A single integer representing the maximum sum of non-adjacent elements.
Example:
Input:
5
3 2 7 10
Output:
13
Key concepts
dynamic_programmingarray
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