Three Duplicates Only

Should have exactly 3 duplicates

Three Duplicates Only

Problem Statement

Given an array of 5 elements, exactly one value must appear exactly 3 times, and all other distinct values must appear exactly 1 time.

For a valid array:

  • Choose one value that appears 3 times
  • The remaining 2 elements must each have unique values (different from each other and from the repeated value)

Constraints

  • Array size: 5 elements
  • Element type: byte (0-255)
  • Pattern: One value appears exactly 3 times, two other values appear exactly 1 time each
  • Total distinct values: 3 (one appearing 3 times, two appearing 1 time each)

Examples

Example 1:

[5, 5, 5, 3, 7]
Valid
Explanation:
- Value 5 appears 3 times ✓
- Value 3 appears 1 time ✓
- Value 7 appears 1 time ✓
- All constraints satisfied

Example 2:

[1, 2, 1, 3, 1]
Valid
Explanation:
- Value 1 appears 3 times (indices 0, 2, 4) ✓
- Value 2 appears 1 time ✓
- Value 3 appears 1 time ✓

Example 3:

[10, 10, 10, 10, 5]
Invalid
Explanation: Value 10 appears 4 times, should be exactly 3

Example 4:

[2, 2, 2, 3, 3]
Invalid
Explanation: Value 2 appears 3 times ✓, but value 3 appears 2 times (should be 1)

Example 5:

[7, 7, 8, 9, 7]
Valid
Explanation:
- Value 7 appears 3 times (indices 0, 1, 4) ✓
- Value 8 appears 1 time ✓
- Value 9 appears 1 time ✓

Example 6:

[0, 0, 0, 0, 0]
Invalid
Explanation: All elements are the same; duplicated value appears 5 times, not 3

Loading the interactive workspace...