Answered step by step
Verified Expert Solution
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 : 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 sssm length
is m 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:
data aaaba "abcba", "abbcde","aaabbbaaaaaac","abcdeffg"
for d in data:
for i in range:
printfd with i max is
maxndi
returns:
aaaba with max is
aaa
aaaba with max is
aaaba
aaaba with max is
aaaba with max is
aaaba with max is
aaaba with max is
abcba with max is
abc
abcba with max is
bcb
abcba with max is
abcba
abcba with max is
abcba with max is
abcba with max is
abbcde with max is
bb
abbcde with max is
abbbbc
abbcde with max is
abbcbbcd
abbcde with max is
abbcdbbcde
abbcde with max is
abbcde
abbcde with max is
aaabbbaaaaaac with max is
aaaaaa
aaabbbaaaaaac with max is
aaabbbaaaaaa
aaabbbaaaaaac with max is
aaabbbaaaaaac
aaabbbaaaaaac with max is
aaabbbaaaaaac with max is
aaabbbaaaaaac with max is
abcdeffg with max is
ff
abcdeffg with max is
effffg
abcdeffg with max is
deffeffg
abcdeffg with max is
cdeffdeffg
abcdeffg with max is
bcdeffcdeffg
abcdeffg with max is
abcdeffbcdeffg
For example, lets find the longest strings with at most different symbols:
aaaba with max is
aaaba
abbcde with max is
abbbbc
aaabbbaaaaaac with max is
aaabbbaaaaaa
abcdeffg with max is
effffg
The first string returns the entire stringthere are only two symbols entirely. The second string
returns the first three abbcde: and abbcde: Including any other symbols would violate
n The second to last string includes every symbol except the last.
Programming Problem : 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 localhelper functions.
Dont use AI to solve this python problem
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started