Skip to main content
LeetCode 2610, Medium. Topics: Array, Hash Table. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 23 parametrized pytest cases, and a playground notebook:

Problem

You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:
  • The 2D array should contain only the elements of the array nums.
  • Each row in the 2D array contains distinct integers.
  • The number of rows in the 2D array should be minimal.
Return the resulting array. If there are multiple answers, return any of them. Note that the 2D array can have a different number of elements on each row.

Examples

Constraints

  • 1 <= nums.length <= 200
  • 1 <= nums[i] <= nums.length

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026