We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def workbook(n, k, arr):
# Write your code here
count = 0
p = 1
for i in range(len(arr)):
sp = 1
cp = 0
q = math.ceil(arr[i] / k)
if k <= arr[i]:
cp += k
else:
cp = arr[i]
for j in range(1,q+1):
if p <= cp and p >= sp:
count += 1
print(sp,cp,p,count)
if cp+k <= arr[i]:
cp += k
else:
cp = arr[i]
sp += k
p += 1
return count
Lisa's Workbook
You are viewing a single comment's thread. Return to all comments →
python 3 solution
def workbook(n, k, arr): # Write your code here count = 0 p = 1 for i in range(len(arr)): sp = 1 cp = 0 q = math.ceil(arr[i] / k) if k <= arr[i]: cp += k else: cp = arr[i] for j in range(1,q+1): if p <= cp and p >= sp: count += 1 print(sp,cp,p,count) if cp+k <= arr[i]: cp += k else: cp = arr[i] sp += k p += 1 return count