Skip to content

Instantly share code, notes, and snippets.

@AashishNandakumar
Last active September 9, 2024 10:38
Show Gist options
  • Save AashishNandakumar/304ee0bea4146299dd0b984959446d67 to your computer and use it in GitHub Desktop.
Save AashishNandakumar/304ee0bea4146299dd0b984959446d67 to your computer and use it in GitHub Desktop.
September 9th 2024 Questions
n = int(input())
respect = [1] * (n + 1)
for i in range(1, n + 1):
p, c = map(int, input().split())
if not c:
respect[i] = respect[p] = 0
res = set(i for i in range(1, n + 1) if respect[i])
if not res:
print(-1)
else:
print(*res)
def twin_permutations():
n = int(input())
a = list(map(int, input().split()))
print(*[n + 1 - a[i] for i in range(n)])
t = int(input())
for _ in range(t):
twin_permutations()
def unit_array():
n = int(input())
a = list(map(int, input().split()))
minus_one_count = a.count(-1)
one_count = a.count(1)
no_of_operations = 0
while minus_one_count > one_count or minus_one_count % 2 != 0:
minus_one_count -= 1
one_count += 1
no_of_operations += 1
print(no_of_operations)
t = int(input())
for _ in range(t):
unit_array()
def grasshopper_on_a_line():
x, k = map(int, input().split())
# logic
if x % k != 0:
print(1)
print(x)
else:
print(2)
print(1, x - 1)
t = int(input())
for _ in range(t):
grasshopper_on_a_line()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment