Transform flat keys into nested dictionary

Quick Overview

This question evaluates proficiency in parsing and restructuring hierarchical parameter keys into nested dictionary structures, string manipulation for grouping, handling nonconforming keys and duplicates, and reasoning about time and space complexity.

Transform flat keys into nested dictionary

Company: Netflix

Role: Machine Learning Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

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.

Quick Answer: This question evaluates proficiency in parsing and restructuring hierarchical parameter keys into nested dictionary structures, string manipulation for grouping, handling nonconforming keys and duplicates, and reasoning about time and space complexity.

|Home/Data Manipulation (SQL/Python)/Netflix
Netflix logo
Netflix
Aug 13, 2025, 12:00 AM
mediumMachine Learning EngineerTechnical ScreenData Manipulation (SQL/Python)
7
0

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.

Loading comments...