Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
A compaction job is handed a list of object-store keys, such as events/2026/03/01/part-000.parquet, and has to know which single folder they all live under, so it can list, lock or rewrite that prefix in one call instead of touching every file. Object stores have no real directories: a folder is just a key prefix that ends at a /, so the answer has to stop at a slash.
Write shared_folder(keys). It takes a list of object keys as strings (in any order, possibly empty) and returns the deepest folder prefix that every key sits under, as a string ending in /, or an empty string when the keys share no folder.
Function to write
shared_folder(keys: list[str]) -> strThe deepest folder prefix shared by every key, ending in a slash, or an empty string.
How to approach it
Find where the keys stop agreeing character by character, then cut that prefix back to its last slash. The smallest and largest key are the only two you need to compare.
Sample cases
+ 3 held back until you submit
two days of one month
The characters agree up to events/2026/03/0, but the shared folder stops at the last slash.
Input
Argument 1
[
'events/2026/03/01/part-000.parquet',
'events/2026/03/01/part-001.parquet',
'events/2026/03/02/part-000.parquet'
]Returns
'events/2026/03/'two files in one partition
The raw prefix runs into the file names (part-00); the folder is the partition itself.
Input
Argument 1
[
'events/2026/03/01/part-000.parquet',
'events/2026/03/01/part-001.parquet'
]Returns
'events/2026/03/01/'top-level folders differ only by case
Keys are case-sensitive, so events/ and Events/ share no folder and the answer is empty.
Input
Argument 1
[
'events/2026/03/01/part-000.parquet',
'Events/2026/03/01/part-000.parquet'
]Returns
''an empty listing
No keys means no shared folder: return an empty string, not None and not an error.
Input
Argument 1
[] (empty list)
Returns
''Constraints
/. Return the longest one shared by every key, trailing slash included: keys under events/2026/03/01/ and events/2026/03/02/ share events/2026/03/.events/2026/03/0, but 0 is not a folder, so cut back to the last / inside it.logs/App/ and logs/app/ are different folders. Do not normalise the keys./. A key with no / at all sits at the bucket root and has no folder."". An empty list also returns "".Worked example
Take "two days of one month": events/2026/03/01/part-000.parquet, events/2026/03/01/part-001.parquet and events/2026/03/02/part-000.parquet. In sort order the smallest is the 01/part-000 key and the largest the 02/part-000 key, and every other key sorts between them, so whatever those two share, all of them share. Walk the two side by side: they agree through events/2026/03/0, then 1 meets 2 and the walk stops. Cut events/2026/03/0 back to its last slash and the answer is events/2026/03/.
The trap is returning the raw character prefix. On "two files in one partition" the characters agree all the way to events/2026/03/01/part-00, which is half a file name, not a folder; the answer is events/2026/03/01/.
What this tests
This is LeetCode 'Longest Common Prefix' (problem 14) in data clothing, with one extra rule: the answer must end at a folder boundary. Target O(n·L) time for n keys of length up to L and O(L) extra space. Comparing only the minimum and maximum key avoids both sorting the list and comparing every key against every other. It is not named in the data engineering interview reports we could find; it is here because object-store prefixes are where a data engineer meets it. A data engineer meets it when choosing the prefix for an object-store listing, a lifecycle rule or a partition rewrite, where a prefix that stops mid-segment points at no folder at all.
shared_folder(keys: list[str]) -> strSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.