6 kyu
Duplicates. Duplicates Everywhere.
1,521 of 2,446bretcameron
Description:
You are given a table, in which every key is a stringified number, and each corresponding value is an array of characters, e.g.
{
"1": ["A", "B", "C"],
"2": ["A", "B", "D", "A"],
}
Create a function that returns a table with the same keys, but each character should appear only once among the value-arrays, e.g.
{
"1": ["C"],
"2": ["A", "B", "D"],
}
Rules
- Whenever two keys share the same character, they should be compared numerically, and the larger key will keep that character. That's why in the example above the array under the key
"2"
contains"A"
and"B"
, as2 > 1
. - If duplicate characters are found in the same array, the first occurance should be kept.
Example 1
input = {
"1": ["C", "F", "G"],
"2": ["A", "B", "C"],
"3": ["A", "B", "D"],
}
output = {
"1": ["F", "G"],
"2": ["C"],
"3": ["A", "B", "D"],
}
Example 2
input = {
"1": ["A"],
"2": ["A"],
"3": ["A"],
}
output = {
"1": [],
"2": [],
"3": ["A"],
}
Example 3
input = {
"432": ["A", "A", "B", "D"],
"53": ["L", "G", "B", "C"],
"236": ["L", "A", "X", "G", "H", "X"],
"11": ["P", "R", "S", "D"],
}
output = {
"11": ["P", "R", "S"],
"53": ["C"],
"236": ["L", "X", "G", "H"],
"432": ["A", "B", "D"],
}
Arrays
Sets
Sorting
Fundamentals
Similar Kata:
Stats:
Created | Apr 8, 2020 |
Published | Apr 8, 2020 |
Warriors Trained | 6580 |
Total Skips | 218 |
Total Code Submissions | 9886 |
Total Times Completed | 2446 |
JavaScript Completions | 1521 |
Python Completions | 689 |
C++ Completions | 136 |
Java Completions | 143 |
Total Stars | 163 |
% of votes with a positive feedback rating | 94% of 395 |
Total "Very Satisfied" Votes | 355 |
Total "Somewhat Satisfied" Votes | 35 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 22 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 8 kyu |