Book Allocation Problem Leetcode Question