You are given a flat collection of parameter keys like ['layer1.attention.q_proj.weight', 'layer1.attention.k_proj.weight', 'layer1.mlp.fc1.weight', ...]. Write a Python function that converts this into a nested dictionary grouped by layer index, placing entries that share the same component path under the same layer (e.g., attention, mlp). Define your grouping rule (e.g., strip the 'layer{n}.' prefix to identify similar components), handle nonconforming keys and duplicates, and analyze time and space complexity.