Skip to content

Instantly share code, notes, and snippets.

@AashishNandakumar
Created August 29, 2024 07:50
Show Gist options
  • Select an option

  • Save AashishNandakumar/95eeb3be0defb38b728dd7a88f2d7155 to your computer and use it in GitHub Desktop.

Select an option

Save AashishNandakumar/95eeb3be0defb38b728dd7a88f2d7155 to your computer and use it in GitHub Desktop.
def dont_try_to_count():
n, m = map(int, input().split())
x = input()
s = input()
"""Approach 1"""
# operations = 0
# while len(x) <= n * m:
# if s in x:
# return operations
# x *= 2
# operations += 1
# else:
# if s in x:
# return operations
# return -1
"""
Approach 2
the worst case is n = 1 and m = 25
then x has to repeat 5 times (2^5) to reach a length > s
-> so just repeat the loop 5 times for every case
"""
for i in range(6):
if s in x:
return i
x *= 2
return -1
t = int(input())
for _ in range(t):
print(dont_try_to_count())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment