Transform flat keys into nested dictionary | Netflix Interview Question