{"id":"4d1a2fcf-952e-424f-bd9c-6aa415b7109d","name":"Maximum Sum Non Adjacent Elements","description":"1. You are given a number n, representing the count of elements.\r\n2. You are given n numbers, representing n elements.\r\n3. You are required to find the maximum sum of a subsequence with no adjacent elements.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"A number representing the maximum sum of a subsequence with no adjacent elements.","constraints":"1 <= n <= 1000\r\n-1000 <= n1, n2, .. n elements <= 1000","sampleCode":{"cpp":{"code":"#"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n}"},"python":{"code":"p"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n5\r\n10\r\n10\r\n100\r\n5\r\n6","sampleOutput":"116","questionVideo":"https://www.youtube.com/embed/VT4bZV24QNo?end=69","hints":[],"associated":[{"id":"3ca1c3e2-7526-4929-ab65-789bdfeb7812","name":"what is time complexity of optimised approach","slug":"what-is-time-complexity-of-optimised-approach","type":4},{"id":"7f8db8f3-3308-465e-a55f-7c5f48179af3","name":"What is the space complexity if we are using solving using space optimised DP?","slug":"what-is-the-space-complexity-if-we-are-using-solving-using-space-optimised-dp","type":4},{"id":"b5c89c18-41fa-4331-922b-c9679f8835bb","name":"what if array has only one element then max sum non adjacent elements will be?","slug":"what-if-array-has-only-one-element-then-max-sum-non-adjacent-elements-will-be","type":4},{"id":"be33a65d-69a8-4a81-b536-790a6c7135c7","name":"what is the time complexity of brute force approach","slug":"what-is-the-time-complexity-of-brute-force-approach","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"e40a1709-77ae-4cd9-a196-92c5fa4efaaf","name":"Maximum Sum Non Adjacent Elements","slug":"maximum-sum-non-adjacent-elements","type":1}],"next":{"id":"0ae78328-c5a0-4d7a-ad0a-9e2f955c555c","name":"Maximum Sum Non Adjacent Elements","type":3,"slug":"maximum-sum-non-adjacent-elements"},"prev":{"id":"a4b36671-7282-4ef5-bd31-5e90926eeb84","name":"Count A+B+C+ Subsequences","type":3,"slug":"count-a-b-c-subsequences"}}}

Maximum Sum Non Adjacent Elements

1. You are given a number n, representing the count of elements. 2. You are given n numbers, representing n elements. 3. You are required to find the maximum sum of a subsequence with no adjacent elements.

{"id":"4d1a2fcf-952e-424f-bd9c-6aa415b7109d","name":"Maximum Sum Non Adjacent Elements","description":"1. You are given a number n, representing the count of elements.\r\n2. You are given n numbers, representing n elements.\r\n3. You are required to find the maximum sum of a subsequence with no adjacent elements.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"A number representing the maximum sum of a subsequence with no adjacent elements.","constraints":"1 <= n <= 1000\r\n-1000 <= n1, n2, .. n elements <= 1000","sampleCode":{"cpp":{"code":"#"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n}"},"python":{"code":"p"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n5\r\n10\r\n10\r\n100\r\n5\r\n6","sampleOutput":"116","questionVideo":"https://www.youtube.com/embed/VT4bZV24QNo?end=69","hints":[],"associated":[{"id":"3ca1c3e2-7526-4929-ab65-789bdfeb7812","name":"what is time complexity of optimised approach","slug":"what-is-time-complexity-of-optimised-approach","type":4},{"id":"7f8db8f3-3308-465e-a55f-7c5f48179af3","name":"What is the space complexity if we are using solving using space optimised DP?","slug":"what-is-the-space-complexity-if-we-are-using-solving-using-space-optimised-dp","type":4},{"id":"b5c89c18-41fa-4331-922b-c9679f8835bb","name":"what if array has only one element then max sum non adjacent elements will be?","slug":"what-if-array-has-only-one-element-then-max-sum-non-adjacent-elements-will-be","type":4},{"id":"be33a65d-69a8-4a81-b536-790a6c7135c7","name":"what is the time complexity of brute force approach","slug":"what-is-the-time-complexity-of-brute-force-approach","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"e40a1709-77ae-4cd9-a196-92c5fa4efaaf","name":"Maximum Sum Non Adjacent Elements","slug":"maximum-sum-non-adjacent-elements","type":1}],"next":{"id":"0ae78328-c5a0-4d7a-ad0a-9e2f955c555c","name":"Maximum Sum Non Adjacent Elements","type":3,"slug":"maximum-sum-non-adjacent-elements"},"prev":{"id":"a4b36671-7282-4ef5-bd31-5e90926eeb84","name":"Count A+B+C+ Subsequences","type":3,"slug":"count-a-b-c-subsequences"}}}
plane

Editor


Loading...

Maximum Sum Non Adjacent Elements

easy

1. You are given a number n, representing the count of elements. 2. You are given n numbers, representing n elements. 3. You are required to find the maximum sum of a subsequence with no adjacent elements.

Constraints

1 <= n <= 1000 -1000 <= n1, n2, .. n elements <= 1000

Format

Input

A number n n1 n2 .. n number of elements

Output

A number representing the maximum sum of a subsequence with no adjacent elements.

Example

Sample Input

6 5 10 10 100 5 6

Sample Output

116

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode