IN PYTHON CODE ONLY & SHOW SCREENSHOT OUTPUTS PLEASE OR WILL DOWNVOTE! Assignment 5 Question 1. Given a string s, return

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

IN PYTHON CODE ONLY & SHOW SCREENSHOT OUTPUTS PLEASE OR WILL DOWNVOTE! Assignment 5 Question 1. Given a string s, return

Post by answerhappygod »

IN PYTHON CODE ONLY & SHOW SCREENSHOT OUTPUTS PLEASE
OR WILL DOWNVOTE!
Assignment 5
Question 1.
Given a string s, return the longest palindromic substring in
s.
Example 1: Input: s = ‘babad’ Output: ‘bab’, ‘aba’ is also
correct (just return one solution, no need to give all possible
solutions)
Note: please use dynamic programming method. Using other methods
will not receive any credit.
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
Q1.py:
class Solution:
def longestPalindrome(self, s):
#input: string
#output: longest Palindrome
return longest
if __name__ == "__main__":
test = Solution()
res = test.longestPalindrome("abcdzdcab")
if res == 'cdzdc':
print('PASS')
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')
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply