Category leaf counts
A storefront keeps its category catalog as a tree. Entry i of children lists the indexes of the direct subcategories of category i, in the order a merchandiser arranged them, and category 0 is the catalog root. A category with no subcategories of its own is a leaf, which is where products actually hang. The navigation bar shows the root's direct subcategories, and each one needs a badge counting the leaf categories underneath it. Return one count per direct subcategory of the root, in the order those subcategories appear in the root's own entry. A subcategory with nothing beneath it is itself a leaf and counts as 1. Indexes can point anywhere in the list, so a subcategory is not guaranteed to sit after its parent. Return an empty list when children is empty or when the root has no subcategories.
taxonomy_branch_leaf_counts(children: list[list[int]]) → list[int][[[1,2],[3,4],[],[],[]]]out[2,1][[[2,1],[],[3,4],[],[]]]out[2,1][[[1],[2],[3],[]]]out[1]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[[[1,2],[3,4],[],[],[]]][2,1]not run yetsample[[[2,1],[],[3,4],[],[]]][2,1]not run yetsample[[[1],[2],[3],[]]][1]not run yetsample