#K10261. Filesystem Hierarchy Builder

    ID: 23208 Type: Default 1000ms 256MiB

Filesystem Hierarchy Builder

Filesystem Hierarchy Builder

You are given a list of file paths, each path containing directory and file names separated by a forward slash (/). Your task is to construct a nested JSON object representing the filesystem hierarchy. In this representation, directories are represented as JSON objects (with keys sorted in lexicographical order) and files are represented by the JSON null value.

The input begins with an integer (N) denoting the number of file paths, followed by (N) lines each containing one file path. The output should be a single line containing the JSON string of the nested filesystem structure.

For example, if the input is:

4
folder1/folder2/file1
folder1/file2
folder3/file3
folder1/folder2/folder3/file4

then the output should be:

{"folder1": {"file2": null, "folder2": {"file1": null, "folder3": {"file4": null}}}, "folder3": {"file3": null}}

Note: All keys in JSON objects must be output in sorted order (lexicographically).

inputFormat

The first line of input contains a single integer (N), the number of file paths. Each of the next (N) lines contains a non-empty string representing a file path. Each path consists of directory names and a file name, separated by the forward slash character '/'.

outputFormat

Output a single line containing the JSON string of the constructed filesystem hierarchy. In the JSON, directories are represented as objects with keys sorted in lexicographical order, and files are represented by null.## sample

4
folder1/folder2/file1
folder1/file2
folder3/file3
folder1/folder2/folder3/file4
{"folder1":{"file2":null,"folder2":{"file1":null,"folder3":{"file4":null}}},"folder3":{"file3":null}}