Question
1) Solve in Python. a. Given a string, consider the prefix string made of the first N chars of the string. Does that prefix string
1) Solve in Python.
a.
Given a string, consider the prefix string made of the first N chars of the string. Does that prefix string appear somewhere else in the string? Assume that the string is not empty and that N is in the range 1..str.length()1
def prefixAgain(str, n):
b.
Given a string, if the same 2-character substring appears at both its beginning and end, return the contents of the string without the 2-character substring at the beginning. For example, "HelloHe" yields "lloHe". Note that the 2-character substring at the beginning may overlap with the one at the end, so "Hi" yields "". If the two characters at the start and end of the string do not match each other, return the original string unchanged.
Examples:
without2("HelloHe") -> "lloHe" without2("HelloHi") -> "HelloHi" without2("Hi") -> ""
def without2(str):
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