Any help with solving the following problem?

I've just started practicing leetcode and I am very rusty. I'm practicing in Python, but I can follow along in any other languages. Much appreciated!

Given a list of dictionaries containing set of ids, find folders and assignments such that the iteration
over the list will produce the sub items of the folders along with hyphen.
Find the results in O(n) time complexity. Also mention about the space complexity as well.

eg:
    input = [
        {"id": 1, "name": "US History", "parent_id": None},
        {"id": 2, "name": "Third Assignment", "parent_id": 3},
        {"id": 3, "name": "First Chapter", "parent_id": 1},
        {"id": 4, "name": "Second Assignment", "parent_id": 1},
        {"id": 5, "name": "First Assignment", "parent_id": 6},
        {"id": 6, "name": "Canadian History", "parent_id": None},
    ]
  output:
	US History
	-First Chapter
	--Third Assignment
	-Second Assignment
	Canadian History
	-First Assignment
Comments (0)