Contest problem: 1423. Maximum Points You Can Obtain from Cards

Shu-Yu Huang
1 min readApr 26, 2020

--

Solution1

Today I joined my first LeetCode contest, pass only 1 easy case, which means I have a large room for improvement.

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 numbers. Each time we should only pick the rightmost or the leftmost.

Minus minimum summary method:
The solution to the problem is to find continuous M-K numbers in the list that has the minimum summary, so the maximum possible summary is the total summary of all numbers minus the minimum summary.

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. If K>0.5*M, use the Minus minimum summary method to reduce the amount of each summary. Else, use the Maximum summary method.
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 exceeds the stored summery.

However, this method exceeds the time requirement.

https://leetcode.com/contest/weekly-contest-186/problems/maximum-points-you-can-obtain-from-cards/

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