Unix Find with Filters and Links
Asked at Amazon· Screen
Reported by the problem's creator, not verified
You work on an in-memory file tree that models a Unix-like file system. A node is one of three kinds:
- a directory
{"name": ..., "children": [...]}, - a file
{"name": ..., "size": ...}, - a symbolic link
{"name": ..., "target": ...}, wheretargetis an absolute path.
The root is a directory named "". Names are non-empty, contain no /, and are unique among siblings. The canonical path of a node is / followed by the names from the root down to it, joined with /; the root's canonical path is /.
A link's target is looked up as a canonical path, without resolving through other links along the way. A target that names no node in the tree (for example one that goes through a link, such as /x/ln/f where /x/ln is a link), or that names another link, is broken.
Examples
Example 1
Input:
{"mode":"and","root":{"name":"","children":[{"name":"docs","children":[{"name":"report.txt","size":900},{"name":"report.pdf","size":5000},{"name":"notes.txt","size":20}]},{"name":"logs","children":[{"name":"app.log","size":7000},{"name":"old","children":[{"name":"app.log.1","size":70000},{"name":"app.txt","size":10}]}]},{"name":"report.bak","size":6000}]},"start":"/","min_size":1000,"name_query":"report","follow_links":false}Output:
["/docs/report.pdf","/report.bak"]Explanation:
report.pdf(5000) andreport.bak(6000) containreportand are strictly above 1000.report.txt(900) fails the size test andnotes.txtfails the name test. The two matching paths come back sorted.