Hi everbody I have a problem with a codefoeces task called "Even Odds" 318A - Чет и нечет with python My code do not work with the test number 8
that is my code
def create(n,k):
numbers=[]
i = 1
o = 1
while i <= n:
if i%2 != 0:
numbers.append(i)
i+=1
while o <= n:
if o%2 == 0:
numbers.append(o)
o+=1
return numbers[k]
####
n, k = map(int, input().split())
print(create(n, k-1))
Can u help me please ?
Your method of listing it out is inefficient. n can go up to 10^12 which will cause your method to exceed time and memory limits. You should instead calculate (if k is less than ceil half of n, which odd number? Else which even number?)