using System.Collections.Generic;
public static void Main()
var input = new Dictionary<int, int[]>
[2] = new[] { 3, 5, 7, 9 },
var output = input.GetPossibleRanges();
foreach (var entry in output)
Console.WriteLine(string.Join(",", entry));
public static class Helpers
public static IEnumerable<List<int>> GetPossibleRanges(this Dictionary<int, int[]> dict)
var ranges = new List<int> { dict.Keys.Min() }.BuildRanges(dict);
public static IEnumerable<List<int>> BuildRanges(this List<int> range, Dictionary<int, int[]> dict)
if (dict.TryGetValue(range.Last(), out int[] nextLevel))
foreach (var child in nextLevel)
foreach (var grownRange in range.Append(child).ToList().BuildRanges(dict))