Book allocation

What is wrong in this code???
I tried submitting at hacker block but it shows wrong answer