Page Allocation Problem Leetcode Javascript Question