Question: Python problem Question 2 ( 32 points ) : Lets be a string. We want to count how many substrings we can find in s,

Python problem Question 2 ( 32 points ) : Lets be aPython problem

Question 2 ( 32 points ) : Lets be a string. We want to count how many substrings we can find in s, such that every substring has at least 2 characters and it begins and ends with the same letter from the 'abc...z' or 'ABC...Z' when ignoring differences between uppercase and lowercase. Example : a4b2aB?' We can find the following substrings: a4 aAb2a Ab2a b2aB Therefore the answer is 4 Write the function check(s) that gets s as a parameter (string) and returns the required number as described Requirements: Time : O(n) whereas n is the length of s. Space : 0(1) Must NOT use lower) nor upper() operations. Remark: if your solution does not keep these requirements, points will be reduced. Hint: if any character c appears x times in the strings, then we know how many strings of length>=2 that begin and end with the same c character begin in location of the first c in s. Also we know how many such strings begin in location of the second c in s and so on. Therefore we know exactly how many strings of length>=2 exist in s such that they begin and end with the same character s

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!