Question :Given an array having 2n elements you can choose n elements from either end of the array such that the values obtained result in maximum sum.
Input : 1 3 100 25 20 4 Output : 103
Approach: Initially, I tried recursive approach by showing both possibilities of an element that it can either be included or excluded, but he told to optimize it and I came up with prefix sum approach.
Idea: The main idea behind the prefix sum approach was if we select ‘x’ elements from left we can select ‘n-x’ elements from the right.
- GOCC14: Google Online Coding Challenge 2020 - New Grad (India)
- GOCC18: Google Online Coding Challenge 2020 - New Grad(India)
- GOCC14: Google's Online Coding Challenge - New Grad (India)
- Huawei Interview Experience | OnSite Interview ( 5 years experienced)
- Amazon Interview Experience | Set 183 (SDE - New Grad Position)
- Atlassian Grad SWE Interview Experience | On Campus FTE
- UBS Grad Interview Experience
- Microsoft Interview Experience | Set 46 (Onsite)
- Amazon Interview Experience | Set 368 (Phone and Onsite)
- Cisco Interview Experience Onsite
- Facebook NYC Onsite Interview Experience
- Freshworks Interview Experience Onsite- SE-1
- Facebook Interview Experience - Menlo Park Onsite
- Lovely Professional University Interview (Campus Placements)
- Sabre Interview Experience at VIT University
- PwC Interview Experience at VIT University
- Paypal Interview for Internship for Data Analytics in VIT University
- Google Internship 2020 - Google Online Challenge(1st Coding Round)
- Google Interview Experience | On-campus 2020
- Why Google Shutters Google+ ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.