Page Allocation Problem Leetcode Javascript Interview