Hackerrank Count Circular Left Shifts
Anonymous User
305

Sorry I forgot to take any pics, but the question is pretty simple:

def countStrings(s: str) -> int:
	...
	return count

The question states that:

  • you have an array of length(s)
  • array[0] = s
  • each index in the rest of the array is one "left-shift" of the previous string
  • you have to count how many strings in the array have first and last character equal.

ex:

s = "abba"
array = ["abba", "bbaa", "baab", "aabb"]
result = 2 

explanation: "abba" and "baab" have first and last char as the same

ex2:

s = "aaabbba"
array = ["aaabbba", "aabbbaa", "abbbaaa", "bbbaaaa", "bbaaaab", "baaaabb", "aaaabbb"]
result = 5

explanation: "aaabbba", "aabbbaa", "abbbaaa", "bbaaaab", "baaaabb"

I forgot the constraints of how long the string could be but it was really long and basically a brute force of creating the strings wouldn't work b/c of TLE. So I'm guessing this is basically a math problem and you shouldn't create new strings, but I had no idea how to solve.

Any ideas??

Comments (1)