using System.Collections.Generic;
var rawData = new List<(int priceIndex, string symbol)>
var numsDictionary = rawData
.GroupBy(entry => entry.symbol)
.ToDictionary(group => group.Key, group => group.Select(e => e.priceIndex).Distinct().Count());
var dataWithNums = rawData
.Select(entry => (entry.priceIndex, entry.symbol, numsDictionary[entry.symbol]))
var grupos = AgruparSimbolos(dataWithNums);
foreach (var grupo in grupos)
Console.WriteLine($"Grupo {grupoIndex}: {{ {string.Join(", ", grupo)} }}");
static List<HashSet<string>> AgruparSimbolos(List<(int priceIndex, string symbol, int nums)> data)
var grupos = new List<HashSet<string>>();
var symbolToGroup = new Dictionary<string, HashSet<string>>();
var priceIndexToGroup = new Dictionary<int, HashSet<string>>();
foreach (var (priceIndex, symbol, _) in data)
HashSet<string> grupo = null;
if (symbolToGroup.TryGetValue(symbol, out var existingGroup))
else if (priceIndexToGroup.TryGetValue(priceIndex, out var groupForPriceIndex))
grupo = groupForPriceIndex;
grupo = new HashSet<string>();
symbolToGroup[symbol] = grupo;
priceIndexToGroup[priceIndex] = grupo;