Implement to build the next array efficiently