Convert an Array into a 2D Array With Conditions - Leetcode 2610 - JAVA