Dsa
Dynamic Programming
Warm-up
Maximal Non-Adjacent Subset Sum
Given an array of integers, find the maximum sum of non-adjacent elements. You can choose to skip elements to maximize the sum, and you cannot select two adjacent values.
Input format:
- The first line contains n, the number of integers in the array.
- The second line contains n integers.
Output format:
- A single integer representing the maximum sum of non-adjacent elements.
Example:
Input:
4
2 4 6 2
Output:
8
Key concepts
dynamic_programminggreedysubset
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