Row Max Unique

Each row has a unique maximum value

Row Max Unique

Problem Statement

Given a 2D array with 4 rows and 5 columns, where each element ranges from 1 to 100, ensure that: 1. Each row has a unique maximum value (the max appears only once in that row) 2. All row maximum values are distinct from each other (no two rows can have the same maximum value)

Your task is to write constraints to generate a 2D array that satisfies these requirements.

Constraints

  • Array dimensions: 4 rows × 5 columns
  • Each element: 1 ≤ element ≤ 100
  • Each row must have exactly one unique maximum value
  • No two rows can share the same maximum value
  • A value that is the maximum of one row may still appear in another row, as long as it is not the maximum there

Examples

Example 1:

Row 0: [10, 25, 15, 20, 18]
Row 1: [30, 35, 28, 32, 34]
Row 2: [40, 45, 42, 43, 44]
Row 3: [50, 51, 48, 49, 47]

Row maxes: [25, 35, 45, 51] ✓
All unique: YES ✓
Max appears once per row: YES ✓

Explanation: Row 0 has max 25 (appears once), Row 1 has max 35 (appears once), Row 2 has max 45 (appears once), Row 3 has max 51 (appears once). All maxes are distinct.

Example 2:

Row 0: [50, 30, 40, 35, 20]
Row 1: [15, 45, 25, 35, 20]
Row 2: [20, 22, 60, 18, 25]
Row 3: [10, 48, 15, 30, 42]

Row maxes: [50, 45, 60, 48] ✓
All unique: YES ✓
Max appears once per row: YES ✓

Explanation: Each row has a distinct maximum with no duplicates within that row.

Example 3 (Invalid):

Row 0: [10, 25, 25, 20, 15]
Row 1: [30, 35, 28, 32, 34]
Row 2: [40, 45, 42, 43, 44]
Row 3: [50, 51, 48, 49, 47]

✗ INVALID: Row 0 has max 25 appearing twice in the same row

Explanation: The value 25 appears twice in Row 0, violating the "unique max in each row" constraint.

Example 4 (Invalid):

Row 0: [10, 45, 15, 20, 12]
Row 1: [30, 35, 28, 32, 34]
Row 2: [40, 45, 42, 43, 44]
Row 3: [50, 51, 48, 49, 47]

Row maxes: [45, 35, 45, 51]
✗ INVALID: Row 0 and Row 2 both have maximum 45

Explanation: Every row here does have a single, non-repeated maximum, so the first requirement holds. The second one does not: Row 0 and Row 2 share the maximum 45, and no two rows may have the same maximum.

Example 5:

Row 0: [10, 25, 15, 20, 12]
Row 1: [30, 35, 28, 32, 25]
Row 2: [40, 45, 42, 43, 44]
Row 3: [50, 51, 48, 49, 47]

Row maxes: [25, 35, 45, 51] ✓
All unique: YES ✓
Max appears once per row: YES ✓

Explanation: This one is valid, and worth studying. The value 25 is Row 0's maximum and it also appears in Row 1 — that is allowed, because in Row 1 it is just an ordinary element (Row 1's maximum is 35). Only the four maximum values have to differ from one another; the rest of the array may repeat them freely.

Loading the interactive workspace...