Skip to content

visual walkthrough

Maximum Points You Can Obtain from Cards

MediumFixed-size Window (Complement)Reported at: GoogleAmazonAdobe

Maximise the ends by minimising the middle window, a neat reframing.

Solve on LeetCode

The idea

You must take k cards, always from the two ends. So whatever you leave behind is one contiguous block of n − k cards in the middle.

Maximising the points you take is the same as minimising the sum of that middle block, which is a fixed-size sliding window.

Complexity

approachtimespace
Try every splitO(k²)O(1)
Smallest middle blockO(n)O(1)

More walkthroughs