Page Allocation Problem Leetcode Javascript