Skip to content

Instantly share code, notes, and snippets.

@AashishNandakumar
Created September 4, 2024 17:31
Show Gist options
  • Save AashishNandakumar/c1aafbb8d8295a6707ee11c4f6351d65 to your computer and use it in GitHub Desktop.
Save AashishNandakumar/c1aafbb8d8295a6707ee11c4f6351d65 to your computer and use it in GitHub Desktop.
September 4th 2024 Questions
# input
n, s = map(int, input().split())
a = [0] + list(map(int, input().split())) + [0]
b = [0] + list(map(int, input().split())) + [0]
# logic
reachable = False
for i in range(1, n + 1):
if i == 1 and a[i] == 0:
print("NO")
break
if i == s and a[i] == 1:
print("YES")
break
if i == s and b[i] == 1:
reachable = True
elif i == s and b[i] != 1:
print("NO")
break
if reachable and a[i] == 1 and b[i] == 1:
print("YES")
break
else:
print("NO")
# input
n, s = map(int, input().split())
a = [0] + list(map(int, input().split())) + [0]
b = [0] + list(map(int, input().split())) + [0]
# logic
if a[1] == 0:
print("NO")
elif a[s] == 1 or (b[s] == 1 and any(a[i] == 1 and b[i] == 1 for i in range(s, n + 1))):
print("YES")
else:
print("NO")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment