Book Allocation Problem Leetcode Solution 1