IN PYTHON CODE ONLY & PLEASE SHOW OUTPUT Question 2: There are piles of coins on the table. The number of coins in each
Posted: Mon May 02, 2022 12:27 pm
IN PYTHON CODE ONLY & PLEASE SHOW
OUTPUT
Question 2:
There are piles of coins on the table. The number of coins in
each pile is known. Please pick up piles to maximize the number of
coins. The restriction is that you cannot pick up coins from
consecutive two piles. The last pile and the first pile are not
connected. Using other methods will not receive any
credit.
Example: Input: [2,7,9,3,1] Output: 12 Explanation: pick up the
first, the third, and the fifth: 2+9+1=12
Q2.py:
class Solution(object):
def pick(self, nums):
"""
input: int list, numbers of
coins
output: maximum number
"""
return maximum
if __name__ == "__main__":
res = Solution().pick([1, 2, 3, 4, 5, 6, 7])
if res == 16:
print('PASS')
OUTPUT
Question 2:
There are piles of coins on the table. The number of coins in
each pile is known. Please pick up piles to maximize the number of
coins. The restriction is that you cannot pick up coins from
consecutive two piles. The last pile and the first pile are not
connected. Using other methods will not receive any
credit.
Example: Input: [2,7,9,3,1] Output: 12 Explanation: pick up the
first, the third, and the fifth: 2+9+1=12
Q2.py:
class Solution(object):
def pick(self, nums):
"""
input: int list, numbers of
coins
output: maximum number
"""
return maximum
if __name__ == "__main__":
res = Solution().pick([1, 2, 3, 4, 5, 6, 7])
if res == 16:
print('PASS')