6 kyu

Unique sets

Description:

Unique Sets

Task:

You are given a list of sets. Each set contains multiple hashable values which can be either simple (e.g., integers, strings) or compound. For the purpose of this task (and in the Python tests), compound values are limited to tuples and frozensets. Compound values may also include nested compound values, and every individual element at any level of nesting must be considered when checking for uniqueness.

Your goal is to determine whether all sets in the list are unique according to the following rules:

  1. No Overlap Across Sets: No value (whether directly in a set or nested within a compound structure) should appear in more than one set. For example, if the number 1 appears as an element in one set and also inside a tuple in another set, this violates uniqueness.

  2. No Duplicates Within a Set: A set is considered non-unique if any value appears more than once within that set—even if one occurrence is nested within a compound structure. For instance, if the value 5 appears both directly and inside a nested tuple within the same set, that set is not unique.

  3. Empty Input: If the input list is empty, return True, as there are no sets to conflict with each other.

Input:

  • An array (list) of sets.
  • Set Contents: Each set contains one or more hashable values. These values can be:
    • Simple values: integers or strings.
    • Compound values(in Python): Tuples and frozensets only. These values may themselves contain nested compound values.

Examples:

[ {5,8 , (1,2), "rvbc" }, {"fnyh", "esa", 1}, {("cev","cdv",0), 18} ] -> False

[ {5,8 , (1,2), "rvbc" }, {"fnyh", "esa", 6}, {("cev","cdv",0), 18} ] -> True

[] -> True

[ {5,8 , (1,2), "rvbc" }, { {"fnyh", 0}, "esa", 6}, {("cev","cdv",0), 18} ] -> False

[ {5,8 , (1,(2,6,(9,100,107),890,(1,(5,6))), (3,4,5)), "rvbc" }, {"fnyh", "esa", 6}, {("cev","cdv",20), 18} ] -> False ( Since "1","6" and "5" appear twice)

Please, be sure to check out my other katas:

Lists
Arrays
Sets

More By Author:

Check out these other kata created by DrillToHeaven

Stats:

CreatedFeb 9, 2025
PublishedFeb 10, 2025
Warriors Trained170
Total Skips6
Total Code Submissions193
Total Times Completed70
Python Completions70
Total Stars6
% of votes with a positive feedback rating93% of 20
Total "Very Satisfied" Votes18
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • DrillToHeaven Avatar
  • bornForThis Avatar
Ad