Computers and Technology

Divisibility of Strings Given two strings, s and t, create a function that operates per the following rules:
1. Find whether string s 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 s is 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.
Example 1
s = 'bcdbcdbcdbcd'
t = 'bcdbcd'
If string tis concatenated twice, the result is 'bcdbcdbcdbcd' which is equal to the string s. 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 sand t. 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 ing s. There is an extra "bcd" in the concatenated string. The string s is not divisible by stringt, so return -1.
Function Description
Complete the function
findSmallestDivisor in the editor below. findSmallestDivisor has the following
parameter(s):
string s: a string
string t: a string
Returns:
int: the length of the smallest string, u, if string s is divisble by string t, or return -1 if not
• 1 s size of ss 2 x 105
• 1 s size of ts 2x105
• size of t s size of s
Input Format Format for Custom
Testing
Sample Case 0
Sample Input
STDIN Function

Irbblrbb arrow s = 'lrbblrbb'
Irbb arrowt = 'lrbb
Sample Output
4
Explanation
If string 'Irbb' is concatenated 2 times, the result is strings, so the string is divisible. If string 'rbb'is concatenated 1 time, the result is string t. The smallest string that can be concatenated some number of times to get both sand t is 'Irbb' with a length of 4.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:00, dramaqueenactr2040
Two technicians are discussing the common u-joint. technician a says its input and output speeds should be equal. technician b says that it normally has two yokes. which technician is correct?
Answers: 1
image
Computers and Technology, 22.06.2019 10:50, whocares1234
A911 dispatcher is the sole sender of messages to all police officers. while on patrol, officers communicate with the dispatcher who, in turn, relays messages to other officers. the officers do not communicate directly with one another. this illustrates a network.
Answers: 1
image
Computers and Technology, 22.06.2019 17:40, math31343
Gabe wants to move text from one document to another document. he should copy the text, paste the text, and open the new document highlight the text, select the cut command, move to the new document, make sure the cursor is in the correct location, and select the paste command select the save as command, navigate to the new document, and click save highlight the text, open the new document, and press ctrl and v
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, jc624826
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
Do you know the correct answer?
Divisibility of Strings Given two strings, s and t, create a function that operates per the followi...

Questions in other subjects: