Skip to content

Practice Convert an Array Into a 2D Array With Conditions

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2610
LeetCode Problem

Convert an Array Into a 2D Array With Conditions

Problem Statement

Place all elements of nums, preserving their occurrence counts, into a two-dimensional array. Every row must contain distinct values, and the number of rows must be as small as possible. Rows may have different lengths. Return any valid arrangement.

Source: Convert an Array Into a 2D Array With Conditions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,3,4,1,2,3,1]
Output
[[1,3,4,2],[1,3],[1]]

# Example 2

Input
nums = [1,2,3,4]
Output
[[4,3,2,1]]

Constraints

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

Related LeetCode Problems

Practice more problems similar to Convert an Array Into a 2D Array With Conditions.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.