[2nd version]Contest problem: 1423. Maximum Points You Can Obtain from Cards

Shu-Yu Huang
1 min readApr 29, 2020

--

Solution 2

The problem I failed stated as followed:
Given a list of numbers (with M cards)and the amount of picking (K), we should return the maximum possible summary of the picked series. Each time we should only pick the rightmost or the leftmost.

Maximum summary method:
This solution is equivalent to finding k (integer) continuous numbers from the leftmost and K-k continuous numbers from the rightmost that has the maximum summary.

So the algorithm is as following:
1. Use the Maximum summary method. The difference of summary between the sequential two series is the first card and the last card. So, add the number of the last card and minus the number of the first card in the previous series.
2. Store the summary of first picking list: pick the 1st to the Kth number
3. Try every other possible case in either of the methods, replace the stored summary with the new one when the calculated summary larger than the stored summery.

https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/discuss/603018/Python-3-calculate-summary-with-replacing-only-2-contents-each-time

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shu-Yu Huang
Shu-Yu Huang

Written by Shu-Yu Huang

AI engineer in Taiwan AI Academy| Former process engineer in TSMC| Former Research Assistance in NYMU| Studying few-shot-learning and GAN

No responses yet

Write a response