Search⌘ K
AI Features

Algorithm Problems in the Screen: The Medium-to-Hard Patterns

Explore the medium-to-hard algorithm patterns that appear in Palantir FDSE screens, including hash maps, two pointers, sliding windows, prefix sums, topological sorting, interval merging and bounded heaps. Start from a correct baseline, pick the pattern whose invariant follows from the problem contract, and explain its time and space costs using clearly defined variables. Write discriminating tests that catch plausible mistakes, such as invalid window shrinking or lost multiplicity.

Counting target-sum contiguous segments among 200,000 signed readings requires different reasoning from ordering jobs with prerequisites, even if both prompts say “process these records.” The first depends on relationships between cumulative sums; the second depends on directed edges. Choose an algorithm whose invariant follows from the contract, then use the constraints to decide whether its extra machinery is worthwhile. A familiar company tag cannot supply that reasoning.

What evidence should guide preparation and selection?

Palantir’s published coding and efficiency guidance emphasizes working code, edge cases, and time and space complexity. The supplied source reproduces that guidance in a secondary compilation, not the direct official pages.

Public preparation accounts support breadth, but differ in emphasis:

  • Aced emphasizes practical maps and strings and deemphasizes graph-heavy tasks.

  • Scaler includes strings and graphs.

  • An Aced candidate account submitted September 7, 2026 describes dependency ordering in a May 2026 onsite, not a screen.

Together, these accounts establish neither a reliable ranking nor numerical frequency estimates for screen questions.

A separate compilation includes a November 2024 FDSE candidate report of a medium hash-map problem in a CodePair screen. This is a concrete preparation example, not an official screen specification.

For each task, carry forward the previous lesson’s contract discipline:

  • State a correct baseline and identify any constraint it violates.

  • Name the maintained state and invariant.

  • Define complexity variables.

  • Choose a test that distinguishes your solution from a plausible mistake.

When do maps and two pointers earn their place?

For first_unique_index(‘swiss’), the contract is case-sensitive Python string code points, with no normalization. Return the original index of the first character occurring exactly once, or None when none qualifies.

Count every character, then scan the original string. Here, s occurs three times; w and i occur once. The result is index 1, for w.

Two tempting alternatives lose required information:

  • A set loses multiplicity.

  • Selecting a unique character without preserving original order can select the wrong one.

Repeatedly counting each character gives an O(n²) baseline. A frequency map takes expected O(n) time and O(u) auxiliary space. Here, n is string length and u is the number of distinct code points.

These costs assume bounded-size keys and expected dictionary behavior, not a worst-case hash-table guarantee.

For pair existence in ascending [-4, -1, 0, 3, 5, 8], target 7, two pointers inspect sums 4, then 7, finding -1 + 8.

  • When the sum is too small, every pair using the current left value and an earlier right position is also too small. Advancing left discards no answer.

  • When the sum is too ...