Dsa
Dynamic Programming
Easy
Max Non-Adjacent Sum
You are given an array of integers `nums`, and your goal is to find the maximum sum you can obtain by selecting non-adjacent elements from the array. Implement a function that reads the array from standard input and prints out the maximum sum that can be obtained. You cannot pick two adjacent numbers.
Input format:
- The first line contains an integer `n` (1 ≤ n ≤ 100).
- The second line contains `n` space-separated integers representing the `nums` array (1 ≤ |nums[i]| ≤ 100).
Output format:
- Print a single integer, the maximum sum that can be obtained.
Example:
Input:
4
3 2 5 10
Output:
15
(You can pick 3 and 10).
Key concepts
dynamic_programmingarraygreedy
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