Book Allocation Problem Leetcode Java