Question: Def Solution(S): Task 2 11 Python English A string is called balanced when every letter occurring in the string, appears both in upper- and lowercase.

Def Solution(S):

Def Solution(S): Task 2 11 Python English A string is called balanced

Task 2 11 Python English A string is called balanced when every letter occurring in the string, appears both in upper- and lowercase. For example, the string "CATattac" is balanced ('a', 'c' and 't' occur in both cases), but "Madam" is not ('d' and 'a' appear only in lowercase). Note that the number of occurrences does not matter. Write a function: def solution (S) that, given a string S of length N, returns the length of the shortest balanced fragment of S. If S does not contain any balanced fragments, the function should return -1. Examples: 1. Given S = "azABaabza", the function should return 5. The shortest balanced fragment of Sis "ABaab". 2. Given S = "Taco Cat", the function should return-1. There is no balanced fragment. 3. Given S = "AcZcbaBz", the function should return 8. The shortest balanced fragment is the whole string. 4. Given S = "abcdefghijklmnopqrstuvwxyz", the function should return -1. Assume that: Nis an integer within the range [1..200); string S consists only of letters ('a'-'z' and/or 'A'-'Z'). In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment

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!