What is wrong with my code?

my code gives correct output for sample input but fails all the test case… can you please tell what is wring with this code?

s should be a[n-1] not 0
also there are some error in allAreAllocated() fucntion

see the modified Code
Modified Code

i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved
if you have more doubts regarding this feel free to ask

if(a[i]>pageLimit) return false;