Book Allocation Problem Leetcode Python