Algorithm · Amazon · Medium
You receive comments, a list of n comments. Each comment carries three fields: its own ID (no two comments share an ID), the ID of its parent comment, and its text. Replies can be nested any number of levels deep, and a comment whose parent ID is - is a top-level (root) comment. The text field may itself contain spaces. Implement print_comments(comments), which renders the entire discussion as a tree, producing one line per comment in the following order and layout: Root…