Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 7 : Same, but Different This problem will ask you to break the problem into smaller, function parts. When solving a complex computing problem,

Problem 7: Same, but Different
This problem will ask you to break the problem into smaller, function parts. When solving a
complex computing problem, we never write one monolithic program. We break the problem
into small, manageable parts and integrate them. For this problem, you are encouraged to look
at previous homeworks too. The task is paradoxically simple. Given a string s0s1sm (length
is m +1) and a number n, return a list of the longest string that has, exactly, n distinct symbols.
Of course, there might be more than one string satisfying this. For example, the code:
1 data =["aaaba", "abcba", "abbcde","aaabbbaaaaaac","abcdeffg"]
2 for d in data:
3 for i in range(1,7):
4 print(f"{d} with {i} max is
{max_n(d,i)}")
returns:
1 aaaba with 1 max is
2[aaa]
3 aaaba with 2 max is
4[aaaba]
5 aaaba with 3 max is
6[]
7 aaaba with 4 max is
8[]
9 aaaba with 5 max is
10[]
11 aaaba with 6 max is
12[]
13 abcba with 1 max is
14[a,b,c]
15 abcba with 2 max is
16[bcb]
17 abcba with 3 max is
18[abcba]
19 abcba with 4 max is
20[]
21 abcba with 5 max is
22[]
23 abcba with 6 max is
24[]
25 abbcde with 1 max is
26[bb]
27 abbcde with 2 max is
28[abb,bbc]
29 abbcde with 3 max is
30[abbc,bbcd]
31 abbcde with 4 max is
32[abbcd,bbcde]
33 abbcde with 5 max is
34[abbcde]
35 abbcde with 6 max is
36[]
37 aaabbbaaaaaac with 1 max is
38[aaaaaa]
39 aaabbbaaaaaac with 2 max is
40[aaabbbaaaaaa]
41 aaabbbaaaaaac with 3 max is
42[aaabbbaaaaaac]
43 aaabbbaaaaaac with 4 max is
44[]
45 aaabbbaaaaaac with 5 max is
46[]
47 aaabbbaaaaaac with 6 max is
48[]
49 abcdeffg with 1 max is
50[ff]
51 abcdeffg with 2 max is
52[eff,ffg]
53 abcdeffg with 3 max is
54[deff,effg]
55 abcdeffg with 4 max is
56[cdeff,deffg]
57 abcdeffg with 5 max is
58[bcdeff,cdeffg]
59 abcdeffg with 6 max is
60[abcdeff,bcdeffg]
For example, lets find the longest strings with at most 2 different symbols:
1 aaaba with 2 max is
2[aaaba]
3 abbcde with 2 max is
4[abb,bbc]
5 aaabbbaaaaaac with 2 max is
6[aaabbbaaaaaa]
7 abcdeffg with 2 max is
8[eff,ffg]
The first string returns the entire stringthere are only two symbols entirely. The second string
returns the first three abbcde[0:3] and abbcde[1:4]. Including any other symbols would violate
n =2. The second to last string includes every symbol except the last.
Programming Problem 7: Same, but Different
Complete the function.
You are strongly encouraged to write several smaller (local) functions to solve this
problem. You cannot write global functions, because the autograder cant determine
what you need.
Look to lecture slides to revise what are local/helper functions.
(Don't use AI to solve this python problem)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions