Book Allocation Problem Leetcode Solution Python