I have recently attended a coding exam where the question was quite simple, given n odd buckets the sum of the items in the 1st and nth items(s1) is similar to the sum of the 2nd and n-1th bucket(s2) where s1=s2=... and so on, accordingly the middle bucket has items less than the s1; s1>nm, the target is to find how many items short we have in order to achieve s1. I have written this code but it did not pass 2 time complexity test cases whereas it did pass many corner base hidden test cases.
if n%2==0:
return 0
else:
return l[0]+l[n-1]-l[int(n/2)-1]
Aucun commentaire:
Enregistrer un commentaire