Book Allocation

My code doesn’t pass all test cases. I don’t know why? I don’t find any error in it. Anyone, please in this.
Here is the code link: