class PackageManager:
Palantir's Learning round. Two posts describe this question, and they may come from one author plus a friend: one is a whole-loop guide partly compiled from other people's reports, the other describes the author's and a friend's Learning rounds. Part 2 comes from that second post only. The interviewer explains what a package manager is (one post: like NPM), shows the class definitions for packages and repositories, and asks you to explain the code before you change it. Documentation is given for every new library or piece of code. One post says the round is an hour, with about 15 minutes of behavioural questions first.
Given — the classes (our setup; ask your interviewer). The posts say class definitions were shown but give no fields, so these are ours, and so are the method names. The editor cannot start threads, so the tests pass in a RecordingExecutor: it runs each request when it is submitted, returns a finished Future, and logs every submit and every blocking Future call (.result(), .exception(), and the wait and as_completed functions). It logs done() and running() checks too: a loop that polls a future until it finishes before the next request is sent is still waiting on it, so the tests count any poll made before the last request is sent as a wait. Polling once every request is out (for example, a pointer walking the queue) is fine. Send requests through the given _get_package_future.
class PackageNotFound(Exception): ...
class Package:
def __init__(self, name: str, version: str, payload: bytes = b""): ...
class Repository:
def __init__(self, name: str, packages=()): ...
def add(self, pkg: Package) -> None: ...
def get(self, name: str) -> Package: ... # one network call; raises PackageNotFound
class RecordingExecutor: # test support
def submit(self, fn, *args) -> Future: ... # .log gets "submit:" / "await:" / "poll:<repo>"
class PackageManager:
def __init__(self, repos, executor): ... # executor is required
def _get_package_future(self, repo, name: str) -> Future: ... # given: one request
def get_package(self, name: str) -> Package: ... # Part 1
def get_package_cached(self, name: str) -> Package: ... # Part 2
Part 1 — Send every request before waiting
get_package(name) is given as the loop the posts quote (with our helper's name):
for repo in self.repos:
try:
return self._get_package_future(repo, name).result()
except PackageNotFound:
continue
raise PackageNotFound(name)
Every request goes over the network and .result() blocks, so the next repository is asked only after the previous one has answered. Explain the code, then rewrite get_package(name) so that every repository's request has been sent before you wait on any of them. Return the package, and raise PackageNotFound if no repository has it. The posts' fix: add every future to a queue or array, then walk it. One poster used a pointer in a while loop and says other ways work too.
Clarify first: if several repositories host the package, should the first one in the list win (what the given loop does) or the first to answer? The posts don't say, so the tests only use packages with one host. You may stop at the first hit or wait on every request.
Not reported, not graded (our analysis). Completion order (as_completed), cancelling requests still in flight after a hit, network errors versus "not found", a cached repository that no longer has the package, and thread safety of the cache. Forward Deployed candidates get a different Learning exercise: see the internal SQL-language page.
Both posts say the interviewer shows the code and asks you to explain it before improving it. Say what each class holds, where the network call happens, and why calling .result() right after creating each future leaves only one request in flight.
Stop calling .result() as soon as each future is created. Add every future to a queue or array first, so every request is sent, then walk the collection calling .result() on each, skipping PackageNotFound, and raise PackageNotFound if no repository has it. One poster walked the queue with a pointer in a while loop and says other ways work too.
One post: the code is long, but the bug is inside the function itself. Do not cache packages, because they can be too large; cache the repository each package lives in, fixing the values stored in the hash table. A cached lookup then fetches the package from that repository.
From two posts, which may come from one author plus a friend. One is a whole-loop guide that its author says was compiled partly from other people's reports; it quotes the given loop as the scenario the Learning round will use word for word. Its author describes their own Learning round only in general terms: the interviewer explained a concept and how it works, gave a function that implements it plus documentation, then showed code and asked them to explain it and make it more efficient. That author went on to the hiring-manager round and calls Learning maybe the easiest of the three onsite rounds. The other post describes the author's and a friend's Learning rounds, names the package manager, and is the only source for Part 2. It gives no outcome, and says everyone seems to be failing Learning; that is one person's impression.
That second post explains that .result() blocks, and that the fix is to put every future in a queue and then walk it; its author used a pointer in a while loop after adding every request to an array, and says other ways work too. Advice from the posts, not observed outcomes: reading a little about threads and thread pools beforehand makes the round easy to follow, and you can ask the interviewer as many clarifying questions as you like.
One post claims a weak Learning round gets this problem repeated by the hiring manager; the other says it heard secondhand that the hiring manager repeats your weakest earlier round. Forward Deployed candidates get a different Learning exercise, an internal SQL-like query language; it has its own page.
Palantir's Learning round. Two posts describe this question, and they may come from one author plus a friend: one is a whole-loop guide partly compiled from other people's reports, the other describes the author's and a friend's Learning rounds. Part 2 comes from that second post only. The interviewer explains what a package manager is (one post: like NPM), shows the class definitions for packages and repositories, and asks you to explain the code before you change it. Documentation is given for every new library or piece of code. One post says the round is an hour, with about 15 minutes of behavioural questions first.
Given — the classes (our setup; ask your interviewer). The posts say class definitions were shown but give no fields, so these are ours, and so are the method names. The editor cannot start threads, so the tests pass in a RecordingExecutor: it runs each request when it is submitted, returns a finished Future, and logs every submit and every blocking Future call (.result(), .exception(), and the wait and as_completed functions). It logs done() and running() checks too: a loop that polls a future until it finishes before the next request is sent is still waiting on it, so the tests count any poll made before the last request is sent as a wait. Polling once every request is out (for example, a pointer walking the queue) is fine. Send requests through the given _get_package_future.
class PackageNotFound(Exception): ...
class Package:
def __init__(self, name: str, version: str, payload: bytes = b""): ...
class Repository:
def __init__(self, name: str, packages=()): ...
def add(self, pkg: Package) -> None: ...
def get(self, name: str) -> Package: ... # one network call; raises PackageNotFound
class RecordingExecutor: # test support
def submit(self, fn, *args) -> Future: ... # .log gets "submit:" / "await:" / "poll:<repo>"
class PackageManager:
def __init__(self, repos, executor): ... # executor is required
def _get_package_future(self, repo, name: str) -> Future: ... # given: one request
def get_package(self, name: str) -> Package: ... # Part 1
def get_package_cached(self, name: str) -> Package: ... # Part 2
Part 1 — Send every request before waiting
get_package(name) is given as the loop the posts quote (with our helper's name):
for repo in self.repos:
try:
return self._get_package_future(repo, name).result()
except PackageNotFound:
continue
raise PackageNotFound(name)
Every request goes over the network and .result() blocks, so the next repository is asked only after the previous one has answered. Explain the code, then rewrite get_package(name) so that every repository's request has been sent before you wait on any of them. Return the package, and raise PackageNotFound if no repository has it. The posts' fix: add every future to a queue or array, then walk it. One poster used a pointer in a while loop and says other ways work too.
Clarify first: if several repositories host the package, should the first one in the list win (what the given loop does) or the first to answer? The posts don't say, so the tests only use packages with one host. You may stop at the first hit or wait on every request.
Part 2 — Cache the repository, not the package
One post describes this part: a lot of code, with the bug inside the function itself. The fix is not to cache packages, because they can be too large, but the repository they live in: fix the values in the hash table. get_package_cached(name) is our small reconstruction of that bug, not the real code, and the separate method is our setup. Its table is keyed by package name and stores the Package. Fix it: keep the table keyed by package name, store which repository has the package (the Repository, its name or its index; your choice), and on a cached lookup fetch the package from that repository. The tests check that a cached lookup asks that repository (asking others too is allowed) and that no value in the table holds a Package.
Not reported, not graded (our analysis). Completion order (as_completed), cancelling requests still in flight after a hit, network errors versus "not found", a cached repository that no longer has the package, and thread safety of the cache. Forward Deployed candidates get a different Learning exercise: see the internal SQL-language page.
This code makes a network call per repository and blocks on each one. How would you make it more efficient?
Can you explain what this code does? (walking through the package and repository class definitions)
There is a bug in the caching logic in this code. Find and fix it.
| Approach | Notes |
|---|---|
| Pointer in a while loop over the collected futures | One poster's traversal after adding every request to an array; the post says other ways work too. |
| Completion order with as_completed or wait(FIRST_COMPLETED) | Our analysis, not reported: returns the fastest repository that has the package instead of the first in the list, which changes the answer when several repositories have it. Ask which one the interviewer wants. |
Interviewer hints: The interviewer explains what a package manager is, shows the class definitions for packages and repositories, asks you to explain the code, and gives documentation for every new library or piece of code, so no background knowledge is needed (one post).
What passers do: The one post with an outcome went on to the hiring-manager round; its author says the interviewer explained a concept, gave a function and documentation, then showed code and asked them to explain it and make it more efficient.; The fix both posts describe: add every future to a queue or array so every request is sent, then walk it calling .result() on each. One poster used a pointer in a while loop and says other ways work too (that post gives no outcome).; Advice from the posts, not observed outcomes: reading a little about threads and thread pools beforehand makes the round easy to follow, and you can ask the interviewer as many clarifying questions as you like.
Why people fail: One post says everyone seems to be failing the Learning round (one person's impression) and claims a weak Learning round gets this problem repeated by the hiring manager; the other post says it heard secondhand that the hiring manager repeats your weakest earlier round.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 11 Palantir questions, refreshed monthly from new candidate reports.