Given a Binary string st and a number k. You have to find the Longest continuous sequence of '0' after repeating Given string K time.
Example 1:
Input: k = 3
st = 100001
Output: 4
Explaination: The string repeated k times 
become 100001100001100001. Here the longest 
continuous sequence of 0 is 4.
Example 2:
Input: k = 4
st = 000
Output: 12
Explaination: When st is repeated 4 times 
it become 000000000000. The longest sequence 
becomes of length 12.
Your Task:
You do not need to read input or print anything. Your task is to complete the function lcsK() which takes k and st as input parameters and returns the length of the longest continuous sequence of 0's after repeating st k times.
Expected Time Complexity: O(|st|)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ |st| ≤ 10^{5}
1 ≤ k ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Dynamic programming

Starter code: #User function Template for python3

class Solution:
    def lcsK(self, k, st):
        # code here

Solutions:
class Solution:

	def lcsK(self, k, st):
		if int(st) > 0:
			s = st * k
			ans = 0
			temp = 0
			s = str(s)
			r = min(2, k)
			for i in range(len(st) * r):
				if s[i] == '0':
					temp = temp + 1
				else:
					ans = max(ans, temp)
					temp = 0
			return ans
		else:
			return len(st) * k


class Solution:

	def lcsK(self, k, s):
		n = len(s)
		if k > 1:
			s += s
			n *= 2
		ans = 0
		i = 0
		while i < n:
			x = 0
			while i < n and s[i] == '0':
				(x, i) = (x + 1, i + 1)
			ans = max(ans, x)
			i += 1
		if k == 1 or ans != n:
			return ans
		else:
			return ans // 2 * k


class Solution:

	def lcsK(self, k, st):
		n = len(st)
		dp = [0] * (n + 1)
		if st[0] == '0':
			dp[0] = 1
		for i in range(1, n):
			if st[i] == '0':
				dp[i] = dp[i - 1] + 1
			else:
				dp[i] = 0
		if dp[n - 1] == n:
			return n * k
		u = 0
		for i in range(n):
			if st[i] == '1':
				u = i - 1
				break
		if u == -1:
			return max(dp)
		else:
			return max(max(dp), dp[n - 1] + dp[u])


class Solution:

	def lcsK(self, k, st):
		if k == 1:
			count = 0
			maxi = 0
			for char in st:
				if char == '0':
					count += 1
					maxi = max(maxi, count)
				else:
					count = 0
			return maxi
		if not '1' in st:
			return k * len(st)
		i = st.index('1')
		st = st[i:] + st[:i]
		count = 0
		maxi = 0
		for char in st:
			if char == '0':
				count += 1
				maxi = max(maxi, count)
			else:
				count = 0
		return maxi


class Solution:

	def lcsK(self, k, st):
		n = len(st)
		(left, bounded, right) = self.getCounts(st, n)
		if k == 1:
			return max(max(left, bounded), right)
		if left + right == n:
			return k * n
		return max(left + right, bounded)

	def getCounts(self, st, n):
		left = 0
		right = 0
		boundedMax = 0
		l = 0
		while l < n:
			if st[l] != '0':
				break
			left += 1
			l += 1
		r = n - 1
		while r >= 0 and r > l:
			if st[r] == '1':
				break
			right += 1
			r -= 1
		curBound = 0
		while l < r:
			if st[l] == '0':
				curBound += 1
				boundedMax = max(boundedMax, curBound)
			else:
				curBound = 0
			l += 1
		return (left, boundedMax, right)


class Solution:

	def lcsK(self, k, st):
		res = []
		i = 0
		while i < len(st):
			if st[i] != '0':
				i += 1
				continue
			cnt = 0
			while i < len(st) and st[i] == '0':
				cnt += 1
				i += 1
			res.append(cnt)
		if st[0] == '1':
			if res:
				return max(res)
			else:
				return 0
		if st[0] == '0' and st[-1] == '0':
			if len(res) == 1:
				return res[0] * k
			return max(res[0] + res[-1], max(res))
		return max(res)


class Solution:

	def lcsK(self, k, st):
		if st.count('0') == len(st):
			return len(st) * k
		if k <= 2:
			b = st * k
		else:
			b = st * 2
		lcs = 0
		olcs = -10 ** 9 - 7
		for i in range(len(b)):
			if b[i] == '0':
				lcs += 1
			else:
				olcs = max(olcs, lcs)
				lcs = 0
		if olcs == 10 ** 9 - 7:
			return lcs
		return olcs


class Solution:

	def lcsK(self, k, st):
		n = len(st)
		count = 0
		for i in range(n):
			if st[i] == '0':
				count += 1
		if count == n:
			return k * n
		xyz = st + st + st
		ans = 0
		lm = 0
		for i in range(len(xyz)):
			if xyz[i] == '0':
				lm += 1
				ans = max(ans, lm)
			else:
				lm = 0
		return ans


class Solution:

	def lcsK(self, k, st):
		st = st + st
		n = len(st)
		here = 0
		mx = 0
		for i in range(n):
			if st[i] == '0':
				here += 1
			else:
				here = 0
			mx = max(mx, here)
		if mx == n:
			return mx * k // 2
		else:
			return mx


class Solution:

	def lcsK(self, k, st):
		p = len(st)
		out = []
		for i in range(len(st)):
			if st[i] == '1':
				out.append(i)
		if len(out) == 0:
			return p * k
		out.append(p + out[0])
		mdif = 0
		for i in range(len(out) - 1):
			v = out[i + 1] - out[i] - 1
			if v > mdif:
				mdif = v
		return mdif


class Solution:

	def findmax(self, st):
		cnt = 0
		ans = 0
		for i in st:
			if i == '0':
				cnt += 1
			else:
				if ans < cnt:
					ans = cnt
				cnt = 0
		if ans < cnt:
			ans = cnt
		return ans

	def lcsK(self, k, st):
		if st[0] != '0' or st[-1] != '0':
			return self.findmax(st)
		(ini, temp, last) = (0, 0, 0)
		cnt = 0
		i = 0
		while i < len(st):
			if st[i] == '0':
				ini += 1
			else:
				break
			i += 1
		temp = ini
		if ini == len(st):
			return len(st) * k
		while i < len(st):
			if st[i] == '0':
				cnt += 1
			else:
				if temp < cnt:
					temp = cnt
				cnt = 0
			i += 1
		last = cnt
		if temp < cnt:
			temp = cnt
		if temp > ini + last:
			return temp
		return ini + last


class Solution:

	def lcsK(self, k, st):
		l = len(st)
		if not '1' in st:
			return k * l
		elif st[0] != '0' or st[-1] != '0':
			count = 0
			mx = 0
			for i in st:
				if i == '0':
					count += 1
				else:
					if count > mx:
						mx = count
					count = 0
			return mx
		else:
			count = 0
			mx = 0
			for i in st:
				if i == '0':
					count += 1
				else:
					if count > mx:
						mx = count
					count = 0
			count = 0
			for i in st:
				if i == '1':
					break
				count += 1
			for i in range(1, l + 1):
				if st[-i] == '1':
					break
				count += 1
			return max(count, mx)