Maximum Sum Subarray from Ends
Given an array of integers and an integer k, find the maximum possible sum by selecting exactly k elements from either the front or back of the array without skipping elements. Elements can only be picked consecutively from the beginning or end of the array.
Asked at:
Oracle
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early February, 2026
Oracle
Senior
You are given an array of integers nums and an integer k. You must pick exactly k elements from the array. At each step, you may pick only from the front or the back of the array. However, you cannot skip elements: To pick an element at index i from the front, all elements before it must already be picked. To pick an element at index j from the back, all elements after it must already be picked. Goal: Return the maximum possible sum of the k selected elements. Example nums = [1, 8, 2, 0, 9, 3] k = 3 Ans = 13 Possible selections: Pick all 3 from the front: 1 + 8 + 2 = 11 Pick 2 from the front, 1 from the back: 1 + 8 + 3 = 12 Pick 1 from the front, 2 from the back: 1 + 3 + 9 = 13 Pick all 3 from the back: 3 + 9 + 0 = 12
Hello Interview Premium
Your account is free and you can post anonymously if you choose.