Skip to content

Instantly share code, notes, and snippets.

@Abuton
Created January 19, 2022 10:10
Show Gist options
  • Save Abuton/779e7271418398532eef2a498f249ba0 to your computer and use it in GitHub Desktop.
Save Abuton/779e7271418398532eef2a498f249ba0 to your computer and use it in GitHub Desktop.
def solution(U, L, C):
# write your code in Python 3.6
if U + L != sum(C):
return "IMPOSSIBLE"
res = [[0 for j in range(len(C))] for i in range(2)]
for i, s in enumerate(C):
if s == 2:
if U == 0 or L == 0:
return "IMPOSSIBLE"
res[0][i] = 1
res[1][i] = 1
U -= 1
L -= 1
elif s == 1:
if U > L:
res[0][i] = 1
U -= 1
else:
res[1][i] = 1
L -= 1
return "".join(map(str, res[0])) + "," + "".join(map(str, res[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment