Question: PLS CODE IN PYTHON 3 WITH COMMENTS 2. Divisibility Of Strings ... Language Python 3 Autocomplete Ready O 1 > #!/bin/python3 - 10 11 #



PLS CODE IN PYTHON 3 WITH COMMENTS
2. Divisibility Of Strings ... Language Python 3 Autocomplete Ready O 1 > #!/bin/python3 - 10 11 # 12 Given two strings, s and to create a function that operates per the following rules: 1. Find whether strings is divisible by string t. String s divisible by string t if string t can be concatenated some number of times to obtain the string s. . If sis divisible, find the smallest string, u, such that it can be concatenated some number of times to obtain both s and t . if it is not divisible, set the return value to -1, 2. Return the length of the string u or -1. . # Complete the 'findSmallestDivisor' function below. # 13 Example 1 S = 'bcdbcdbcdbcd t = 'bcdbcd 14 # The function is expected to return an INTEGER. 15 # The function accepts following parameters: 16 # 1. STRINGS 17 # 2. STRING t 18 # 19 20 def findSmallestDivisor(s, t): 21 # Write your code here 22 23 > if name__ == 'main : - If string tis concatenated twice, the result is 'bcdbcdbcdbcd' which is equal to the strings. The string s is divisible by string t. Since it passes the first test, look for the smallest string, u, that can be concatenated to create both strings sandt The string 'bcd' is the smallest string that can be concatenated to create both strings sandt. The length of the string u is 3, which is the integer value to return. Example 2 S="bcdbcdbcd" t = "bcdbcd" If string t is concatenated twice, the result is "bcdbcdbcdbcd" which is greater than string s. There is an extra "bcd" in the concatenated string. The strings is not divisible by string , so return -1. Function Description Complete the function findSmallest Divisor in the editor below. Line: 10 col: Test Results findSmallestDivisor has the following parameter(s): Custom Innut Run Code Submit Run Tests ? findSmallestDivisor has the following parameter(s): string s: a string string ta string Returns: int: the length of the smallest string, u, if string s is divisble by string t, or return-1 if not Language Python 3 Autocomplete Ready O 1 >#!/bin/python3 - 10 11 12 # Complete the 'findSmallestDivisor' function below. Constraints 13 # 14 1 s size of ss 2 x 105 1 s size ofts 2x105 size oft s size of s 15 # The function is expected to return an INTEGER. # The function accepts following parameters: 1. STRINGS 16 # 17 # 2. STRING t 18 # Input Format Format for Custom Testing The first line contains a single string s. The second line contains a single string t. 19 20 def findSmallestDivisor(s, t): 21 # Write your code here 22 23 > if __name__ == '__main__':-. Sample Case 0 Sample Input STDIN Function Irbblrbb trbb S = 'lrbblrbb t = 'lrbb! Sample Output 4 Explanation If string 'lrbb' is concatenated 2 times, the result is string s, so the string is divisible. If string 'Irbb' is concatenated 1 time, the result is string t. The smallest string that can be concatenated some number of times to get both sand tis'lrb with a length of 4. Line: 10 Sample Case 1 Sample Input Test Results Custom Innut Run Code Run Tests Sub Input Format Format for Custom Testing The first line contains a single string s. The second line contains a single string t. # Sample Case 0 Sample Input STDIN Function Language Python 3 Autocomplete Ready O 1 > #!/bin/python3... 10 11 12 # Complete the 'findSmallestDivisor' function below. 13 # The function is expected to return an INTEGER. 15 # The function accepts following parameters: 16 1. STRINGS 17 2. STRING 18 # # 14 Irbblrbb + 5 = 'lrbblrbb' Irbb + t = 'lrbb # # Sample Output 19 4 20 21 def findSmallestDivisor(s, t): # Write your code here 22 Explanation If string '/bb' is concatenated 2 times, the result is strings, so the string is divisible. If string 'Wrbb is concatenated 1 time, the result is string t. The smallest string that can be concatenated some number of times to get both s and t is 'Irbb' with a length of 4. 23 > if __name__ == '__main__':. Sample Case 1 Sample Input STDIN Function rbrb rbrb 5 = 'rbrb' t = 'rbrbi Sample Output 2 Explanation Line: 10 The strings are equal, so sis divisible by t. If string 'rb'is concatenated 2 times, the result is string sand string t. This is the smallest string that meets the criteria. Test Results Custom Input Run Code Run Tests Su
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
