Comment thread depth
A discussion board keeps every comment on an article in one chronological list. Entry i of parent_of holds the position of the comment that comment i replies to, or -1 when comment i starts a new thread at the top level. An article can carry several top level comments, and moderators reinstate hidden replies, so a comment is not guaranteed to appear after the one it answers: a parent can sit at a later position than its child. The renderer needs an indent level for every comment. Return a list of the same length in which entry i is the depth of comment i, counting 0 for a top level comment, 1 for a direct reply, 2 for a reply to a reply, and so on. Keep the results in input index order. The input always describes a valid structure with no cycles.
comment_reply_depths(parent_of: list[int]) → list[int][[-1,0,0,1]]out[0,1,1,2][[-1,-1,1]]out[0,0,1][[2,-1,1]]out[2,0,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,0,0,1]][0,1,1,2]not run yetsample[[-1,-1,1]][0,0,1]not run yetsample[[2,-1,1]][2,0,1]not run yetsample